Skip to content

Commit

Permalink
x86-linux-setup.c: Use POSIX basename API
Browse files Browse the repository at this point in the history
Musl C library only supports POSIX basename function. while glibc has
both GNU extention as well as POSIX basename implemented. Switch to
using posix version, so it can work across musl and glibc

basename prototype has been removed from string.h from latest musl [1]
compilers e.g. clang-18/GCC-14 flags the absense of prototype as error.
therefore include libgen.h for providing it.

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Simon Horman <horms@kernel.org>
  • Loading branch information
kraj authored and horms committed Jun 18, 2024
1 parent 2e8a93a commit 4fd0553
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions kexec/arch/i386/x86-linux-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
*/
#define _GNU_SOURCE
#include <libgen.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -329,12 +330,14 @@ static int add_edd_entry(struct x86_linux_param_header *real_mode,
memset(edd_info, 0, sizeof(struct edd_info));

/* extract the device number */
if (sscanf(basename(sysfs_name), "int13_dev%hhx", &devnum) != 1) {
char* sysfs_name_copy = strdup(sysfs_name);
if (sscanf(basename(sysfs_name_copy), "int13_dev%hhx", &devnum) != 1) {
fprintf(stderr, "Invalid format of int13_dev dir "
"entry: %s\n", basename(sysfs_name));
"entry: %s\n", basename(sysfs_name_copy));
free(sysfs_name_copy);
return -1;
}

free(sysfs_name_copy);
/* if there's a MBR signature, then add it */
if (file_scanf(sysfs_name, "mbr_signature", "0x%x", &mbr_sig) == 1) {
real_mode->edd_mbr_sig_buffer[*current_mbr] = mbr_sig;
Expand Down

0 comments on commit 4fd0553

Please sign in to comment.