include libgen.h for basename API
PATCH 1/1 include libgen.h for basename API
Musl does no more provide it via string.h therefore builds with newer compilers e.g. clang-18 fails due to missing prototype for basename therefore add libgen.h to included headers list
--- Monitor.c | 1 + platform-intel.c | 1 + super-intel.c | 1 + 3 files changed, 3 insertions(+)
Monitor.c +1 -0
@@ -26,6 +26,7 @@#include "udev.h" #include "md_p.h" #include "md_u.h" +#include <libgen.h> #include <sys/wait.h> #include <limits.h> #include <syslog.h>
platform-intel.c +1 -0
@@ -19,6 +19,7 @@#include "mdadm.h" #include "platform-intel.h" #include "probe_roms.h" +#include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
super-intel.c +1 -0
@@ -23,6 +23,7 @@#include "dlink.h" #include "sha1.h" #include "platform-intel.h" +#include <libgen.h> #include <values.h> #include <scsi/sg.h> #include <ctype.h>
Signature · 1 line
2.44.0
Quoted 16 lines · On Sun, 24 Mar 2024 23:15:37 -0700 Khem Raj <[email protected]> wrote:
Musl does no more provide it via
string.htherefore builds with newer compilers e.g. clang-18 fails due to missing prototype for basename therefore addlibgen.hto included headers listSigned-off-by Khem Raj <[email protected]>--- Monitor.c | 1 + platform-intel.c | 1 + super-intel.c | 1 + 3 files changed, 3 insertions(+)Monitor.c +0
-0
Monitor.c line 32
Quoted 7 lines
Monitor.c +1
-0@@ -26,6 +26,7 @@#include "udev.h" #include "md_p.h" #include "md_u.h" +#include <libgen.h> #include <sys/wait.h> #include <limits.h> #include <syslog.h>
Please stick to style around.
Quoted 17 lines
platform-intel.c +1
-0@@ -19,6 +19,7 @@#include "mdadm.h" #include "platform-intel.h" #include "probe_roms.h" +#include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <string.h> super-intel.c +0
-0
super-intel.c line 29
Quoted 7 lines
super-intel.c +1
-0@@ -23,6 +23,7 @@#include "dlink.h" #include "sha1.h" #include "platform-intel.h" +#include <libgen.h> #include <values.h> #include <scsi/sg.h> #include <ctype.h>
https://man7.org/linux/man-pages/man3/basename.3.html
There are two different versions of basename() - the POSIX version described above, and the GNU version [...]
In the glibc implementation, the POSIX versions of these functions modify the path argument, and segfault when called with a static string such as "/usr/".
I checked my string.h header (opensuse 15 sp4) and there is:
/* Return the file name within directory of FILENAME. We don't
declare the function if the `basename' macro is available (defined in <libgen.h>) which makes the XPG version of this function available. */
It means that with libgen.h header we will switch to XPG/POSIX basename everywhere, even if that is not wanted.
Eventually, you can try to minimize impact, by adding it only if it is absolutely necessary i.e. basename() is not available:
#ifndef basename
#include <libgen.h>
#endif
(not tested, partially copied from string.h)
Please analyze all usages to determine if POSIX version of basename usages are safe- I would like to have that documented in commit message.
Thanks,
Mariusz