cgsecurity / testdisk

TestDisk & PhotoRec
https://www.cgsecurity.org/
GNU General Public License v2.0
1.68k stars 205 forks source link

testdisk-7.2 fails to build with musl-1.2.5: hdaccess.c:1016:7: error: call to undeclared function 'basename'; ISO C99 #154

Closed ernsteiswuerfel closed 6 months ago

ernsteiswuerfel commented 6 months ago

testdisk-7.2 fails to build on musl-1.2.5 systems:

[...]
clang -DHAVE_CONFIG_H -I. -I..     -Os -march=x86-64-v2 -pipe -Wdeclaration-after-statement -Wall -Wextra -MD -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wwrite-strings -W -Wcast-align -Waggregate-return -Wbad-function-cast -Wcast-qual -Wundef -Wredundant-decls -Wsign-compare -Wnested-externs -Winline -Wdisabled-optimization -Wfloat-equal -Wmissing-format-attribute -Wmultichar -Wc++-compat -Wformat=2 -Wtrampolines -Wunreachable-code -Wvla -fstack-protector-strong  -c -o hdaccess.o hdaccess.c
warning: unknown warning option '-Wtrampolines' [-Wunknown-warning-option]
In file included from hdaccess.c:60:
./common.h:42:19: warning: unknown attribute 'gcc_struct' ignored
      [-Wunknown-attributes]
   42 | } __attribute__ ((gcc_struct, __packed__));
      |                   ^~~~~~~~~~
hdaccess.c:163:19: warning: unknown attribute 'gcc_struct' ignored
      [-Wunknown-attributes]
  163 | } __attribute__ ((gcc_struct, __packed__));
      |                   ^~~~~~~~~~
hdaccess.c:1016:7: error: call to undeclared function 'basename'; ISO C99
      and later do not support implicit function declarations [-Wimplicit-function-declaration]
 1016 |       basename (disk_car->device), file);
      |       ^
hdaccess.c:1016:7: warning: format specifies type 'char *' but the argument
      has type 'int' [-Wformat]
 1015 |   snprintf (name_buf, 127, "/sys/block/%s/device/%s",
      |                                        ~~
      |                                        %d
 1016 |       basename (disk_car->device), file);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
hdaccess.c:1068:18: warning: unknown attribute 'gcc_struct' ignored
      [-Wunknown-attributes]
 1068 | } __attribute__((gcc_struct,__packed__)) scsi_inquiry_data_t;
      |                  ^~~~~~~~~~
hdaccess.c:1137:76: warning: unused parameter 'verbose'
      [-Wunused-parameter]
 1137 | static void disk_get_model(const int hd_h, disk_t *dev, const unsigned int verbose)
      |                                                                            ^
hdaccess.c:1616:56: warning: unused parameter 'buf' [-Wunused-parameter]
 1616 | static int file_nopwrite(disk_t *disk_car, const void *buf, const unsigned int count, co...
      |                                                        ^
7 warnings and 1 error generated.
make[2]: *** [Makefile:2238: hdaccess.o] Error 1
make[2]: Leaving directory '/var/tmp/portage/app-admin/testdisk-7.2/work/testdisk-7.2/src'
make[1]: *** [Makefile:450: all-recursive] Error 1
make[1]: Leaving directory '/var/tmp/portage/app-admin/testdisk-7.2/work/testdisk-7.2'
make: *** [Makefile:389: all] Error 2

This is Gentoo downstream bugreport #931887.

Build log attached. testdisk-7.2:20240513-205000.log

cgsecurity commented 6 months ago

Does it compile if you add in hdaccess.c ?

include

ernsteiswuerfel commented 6 months ago

Yes, that fixes the build!

cgsecurity commented 6 months ago

Thanks for reporting the problem and testing the fix.