Skip to content

Conversation

@neuschaefer
Copy link
Contributor

This PR is slightly more complex, but makes it possible to build ampart on musl-libc-based systems such as Alpine Linux

This header exists in glibc, but otherwise isn't particularly portable.
For example it doesn't exist in musl-libc. Fortunately, it isn't actually
needed.
The basename(3) manpage states:

       There are two different versions of basename() - the POSIX version
       described above, and the GNU version, which one gets after

               #define _GNU_SOURCE         /* See feature_test_macros(7) */
               #include <string.h>

       The GNU version never modifies its argument, and returns the empty
       string when path has a trailing slash, and in particular also when it
       is "/".  There is no GNU version of dirname().

       With glibc, one gets the POSIX version of basename() when <libgen.h> is
       included, and the GNU version otherwise.

Using the POSIX version is more portable: For example, musl-libc only
implements the POSIX version and not the GNU version.

Regarding memory management, basename(3) says:

       These functions may return pointers to statically allocated memory
       which may be overwritten by subsequent calls.  Alternatively, they may
       return a pointer to some part of path, so that the string referred to
       by path should not be modified or freed until the pointer returned by
       the function is no longer required.
@7Ji
Copy link
Owner

7Ji commented Mar 3, 2025

It's 2AM here and I can't verify this tonight. Would review this later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this should be removed, I didn't require the header. It was probably added by clangd by accident in 0fa8598

@7Ji 7Ji closed this in e6acead Mar 4, 2025
7Ji added a commit that referenced this pull request Mar 4, 2025
closes #23

Co-authored-by: J. Neuschäfer <j.ne@posteo.net>
@neuschaefer
Copy link
Contributor Author

Thanks a lot!

@neuschaefer neuschaefer deleted the posix branch March 4, 2025 10:00
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.

2 participants