Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support POSIX basename() from musl libc #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hauke
Copy link

@hauke hauke commented Apr 14, 2024

Musl libc 1.2.5 removed the definition of the basename() function from string.h and only provides it in libgen.h as the POSIX standard defines it.

This change fixes compilation with musl libc 1.2.5.

build_dir/target-mips_24kc_musl/tini-0.19.0/src/tini.c:227:36: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
  227 |         fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
build_dir/target-mips_24kc_musl/tini-0.19.0/src/tini.c:227:25: error: format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Werror=format=]
  227 |         fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
      |                        ~^          ~~~~~~~~~~~~~~
      |                         |          |
      |                         char *     int
      |                        %d

basename() modifies the input string, copy it first with strdup(), If strdup() returns NULL the code will handle it.

Musl libc 1.2.5 removed the definition of the basename() function from
string.h and only provides it in libgen.h as the POSIX standard
defines it.

This change fixes compilation with musl libc 1.2.5.
````
build_dir/target-mips_24kc_musl/tini-0.19.0/src/tini.c:227:36: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
  227 |         fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
build_dir/target-mips_24kc_musl/tini-0.19.0/src/tini.c:227:25: error: format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Werror=format=]
  227 |         fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING);
      |                        ~^          ~~~~~~~~~~~~~~
      |                         |          |
      |                         char *     int
      |                        %d

````

basename() modifies the input string, copy it first with strdup(), If
strdup() returns NULL the code will handle it.

Signed-off-by: Hauke Mehrtens <[email protected]>
teddybeermaniac added a commit to teddybeermaniac/Docker.ScratchBase that referenced this pull request Jul 28, 2024
* Used alpine:3.20.2 for base.
* Added a patch for tini - krallin/tini#223.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant