zip: fix build with clang 16

Fix implicit declarations of `memset` and `open/closedir` resulting in
incorrect feature detection and conflicts with libc headers.

+45 -2
+9 -2
pkgs/tools/archivers/zip/default.nix
··· 13 13 ]; 14 14 sha256 = "0sb3h3067pzf3a7mlxn1hikpcjrsvycjcnj9hl9b1c3ykcgvps7h"; 15 15 }; 16 - patchPhase = '' 16 + prePatch = '' 17 17 substituteInPlace unix/Makefile --replace 'CC = cc' "" 18 18 ''; 19 19 ··· 26 26 "INSTALL=cp" 27 27 ]; 28 28 29 - patches = lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ]; 29 + patches = [ 30 + # Trying to use `memset` without declaring it is flagged as an error with clang 16, causing 31 + # the `configure` script to incorrectly define `ZMEM`. That causes the build to fail due to 32 + # incompatible redeclarations of `memset`, `memcpy`, and `memcmp` in `zip.h`. 33 + ./fix-memset-detection.patch 34 + # Implicit declaration of `closedir` and `opendir` cause dirent detection to fail with clang 16. 35 + ./fix-implicit-declarations.patch 36 + ] ++ lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ]; 30 37 31 38 buildInputs = lib.optional enableNLS libnatspec 32 39 ++ lib.optional stdenv.isCygwin libiconv;
+21
pkgs/tools/archivers/zip/fix-implicit-declarations.patch
··· 1 + --- a/unix/configure 2009-04-16 15:25:12.000000000 -0400 2 + +++ b/unix/configure 2023-05-30 15:18:33.670321348 -0400 3 + @@ -408,7 +408,7 @@ 4 + echo Check for errno declaration 5 + cat > conftest.c << _EOF_ 6 + #include <errno.h> 7 + -main() 8 + +int main() 9 + { 10 + errno = 0; 11 + return 0; 12 + @@ -419,6 +419,8 @@ 13 + 14 + echo Check for directory libraries 15 + cat > conftest.c << _EOF_ 16 + +#include <sys/types.h> 17 + +#include <dirent.h> 18 + int main() { return closedir(opendir(".")); } 19 + _EOF_ 20 + 21 +
+15
pkgs/tools/archivers/zip/fix-memset-detection.patch
··· 1 + diff -ur a/unix/configure b/unix/configure 2 + --- a/unix/configure 2008-06-19 21:32:20.000000000 -0600 3 + +++ b/unix/configure 2023-07-11 10:02:57.809867694 -0600 4 + @@ -519,7 +519,10 @@ 5 + 6 + 7 + echo Check for memset 8 + -echo "int main(){ char k; memset(&k,0,0); return 0; }" > conftest.c 9 + +cat > conftest.c << _EOF_ 10 + +#include <string.h> 11 + +int main(){ char k; memset(&k,0,0); return 0; } 12 + +_EOF_ 13 + $CC -o conftest conftest.c >/dev/null 2>/dev/null 14 + [ $? -ne 0 ] && CFLAGS="${CFLAGS} -DZMEM" 15 +