Skip to content

Instantly share code, notes, and snippets.

@marslo
Last active December 12, 2024 10:11
Show Gist options
  • Save marslo/70a3f6728633c49bed865da684378b31 to your computer and use it in GitHub Desktop.
Save marslo/70a3f6728633c49bed865da684378b31 to your computer and use it in GitHub Desktop.
build info-zip from source

get source

$ wget ftp://ftp.info-zip.org/pub/infozip/src/zip30.zip
$ unzip zip30.zip

apply patch

$ curl -fsSL https://gist.githubusercontent.com/marslo/70a3f6728633c49bed865da684378b31/raw/cf402112315ededbfb58c0e17629e9a74708e370/zipinfo.patch
$ cd zip30
$ patch -u zipnote.c -i ../zipinfo.patch

build from source

$ make -f unix/Makefile generic
sh unix/configure "cc" "-I. -DUNIX " ""
Check C compiler type (optimization options)
  GNU C (-O3)
Check bzip2 support
  Check for bzip2 in bzip2 directory
  Check if OS already has bzip2 library installed
-- OS supports bzip2 - linking in bzip2
Check for the C preprocessor
Check if we can use asm code
Check for ANSI options
Check for prototypes
Check the handling of const
Check for time_t
Check for size_t
Check for off_t
Check size of UIDs and GIDs
(Now zip stores variable size UIDs/GIDs using a new extra field.  This
 tests if this OS uses 16-bit UIDs/GIDs and so if the old 16-bit storage
 should also be used for backward compatibility.)
  s.st_uid is 4 bytes
  s.st_gid is 4 bytes
-- UID not 2 bytes - disabling old 16-bit UID/GID support
Check for Large File Support
  off_t is 8 bytes
-- yes we have Large File Support!
Check for wide char support
-- have wchar_t - enabling Unicode support
Check for gcc no-builtin flag
Check for rmdir
Check for strchr
Check for strrchr
Check for rename
Check for mktemp
Check for mktime
Check for mkstemp
Check for memset
Check for memmove
Check for strerror
Check for errno declaration
Check for directory libraries
Check for readlink
Check for directory include file
Check for nonexistent include files
Check for term I/O include file
Check for valloc
Check for /usr/local/bin and /usr/local/man
Check for OS-specific flags
Check for symbolic links
eval /Applications/Xcode.app/Contents/Developer/usr/bin/make -f unix/Makefile zips `cat flags`
cc -c -I. -DUNIX -O3 -DBZIP2_SUPPORT -DUIDGID_NOT_16BIT -DLARGE_FILE_SUPPORT -DUNICODE_SUPPORT -DNO_RMDIR -DNO_STRCHR -DNO_STRRCHR -DNO_RENAME -DNO_MKTEMP -DNO_MKTIME -DNO_MKSTEMP -DZMEM -DNO_ERRNO -DNO_DIR -DHAVE_DIRENT_H -DHAVE_TERMIOS_H -DNO_VALLOC zip.c
In file included from zip.c:16:
./zip.h:726:10: error: conflicting types for 'memset'
  726 |    char *memset OF((char *, int, unsigned int));
      |          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_string.h:74:7: note: previous declaration is here
   74 | void    *memset(void *__b, int __c, size_t __len);
      |          ^
In file included from zip.c:16:
./zip.h:727:10: error: conflicting types for 'memcpy'
  727 |    char *memcpy OF((char *, char *, unsigned int));
      |          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_string.h:72:7: note: previous declaration is here
   72 | void    *memcpy(void *__dst, const void *__src, size_t __n);
      |          ^
In file included from zip.c:16:
./zip.h:728:8: error: conflicting types for 'memcmp'
  728 |    int memcmp OF((char *, char *, unsigned int));
      |        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_string.h:71:6: note: previous declaration is here
   71 | int      memcmp(const void *__s1, const void *__s2, size_t __n);
      |          ^
zip.c:239:11: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  239 | local int finish(e)
      |           ^
zip.c:330:6: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  330 | void ziperr(c, h)
      |      ^
zip.c:440:6: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  440 | void error(h)
      |      ^
zip.c:448:12: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  448 | local void handler(s)
      |            ^
zip.c:466:6: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  466 | void zipmessage_nl(a, nl)
      |      ^
zip.c:505:6: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  505 | void zipmessage(a, b)
      |      ^
zip.c:526:6: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
  526 | void zipwarn(a, b)
      |      ^
zip.c:1031:12: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
 1031 |     printf(text[i]);
      |            ^~~~~~~
zip.c:1031:12: note: treat the string as an argument to avoid this
 1031 |     printf(text[i]);
      |            ^
      |            "%s", 
zip.c:1228:12: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
 1228 |     printf(cryptnote[i]);
      |            ^~~~~~~~~~~~
zip.c:1228:12: note: treat the string as an argument to avoid this
 1228 |     printf(cryptnote[i]);
      |            ^
      |            "%s", 
zip.c:1282:11: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1282 | local int check_unzip_version(unzippath)
      |           ^
zip.c:1326:12: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1326 | local void check_zipfile(zipname, zippath)
      |            ^
zip.c:1531:11: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1531 | local int add_filter(flag, pattern)
      |           ^
zip.c:1646:12: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1646 | local long add_name(filearg)
      |            ^
zip.c:1786:5: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1786 | int encr_passwd(modeflag, pwbuf, size, zfn)
      |     ^
zip.c:1825:5: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1825 | int rename_split(temp_name, out_path)
      |     ^
zip.c:1845:5: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 1845 | int set_filetype(out_path)
      |     ^
zip.c:2119:5: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
 2119 | int main(argc, argv)
      |     ^
17 warnings and 3 errors generated.
make[1]: *** [zip.o] Error 1
make: *** [generic] Error 2

references:

diff -pur zip30/unix/configure zip30-patched/unix/configure
--- zip30/unix/configure 2008-06-20 05:32:20
+++ zip30-patched/unix/configure 2023-10-04 10:46:52
@@ -513,13 +513,16 @@ do
do
echo Check for $func
echo "int main(){ $func(); return 0; }" > conftest.c
- $CC $BFLAG -o conftest conftest.c >/dev/null 2>/dev/null
+ $CC $BFLAG -Wno-implicit-function-declaration -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGS="${CFLAGS} -DNO_`echo $func | tr '[a-z]' '[A-Z]'`"
done
echo Check for memset
-echo "int main(){ char k; memset(&k,0,0); return 0; }" > conftest.c
+cat > conftest.c << _EOF_
+#include <string.h>
+int main(){ char k; memset(&k,0,0); return 0; }
+_EOF_
$CC -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGS="${CFLAGS} -DZMEM"
@@ -556,6 +559,7 @@ cat > conftest.c << _EOF_
echo Check for directory libraries
cat > conftest.c << _EOF_
+#include <dirent.h>
int main() { return closedir(opendir(".")); }
_EOF_
@@ -578,7 +582,10 @@ echo Check for readlink
# Dynix/ptx 1.3 needed this
echo Check for readlink
-echo "int main(){ return readlink(); }" > conftest.c
+cat > conftest.c << _EOF_
+#include <unistd.h>
+int main(){ return readlink(); }
+_EOF_
$CC -o conftest conftest.c >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
$CC -o conftest conftest.c -lseq >/dev/null 2>/dev/null
--- unix/configure 2024-12-12 01:49:36.095513032 -0800
+++ unix/configure.bak 2024-12-12 01:45:50.579139000 -0800
@@ -2498,7 +2498,7 @@
do
echon "Check for ${func}()..."
echo "int main(){ $func(); return 0; }" > conftest.c
- $CC $BFLAG -Wno-implicit-function-declaration -o conftest conftest.c >/dev/null 2>/dev/null
+ $CC_TST $CFLAGS $BIF_TST -o conftest conftest.c >/dev/null 2>/dev/null
status=$?
if [ $status -ne 0 ]; then
ucname=` echo ${func} | tr '[a-z]' '[A-Z]' `
@@ -2544,10 +2544,7 @@
# Check for memset().
echon 'Check for memset()...'
-cat > conftest.c << _EOF_
-#include <string.h>
-int main(){ char k; memset(&k,0,0); return 0; }
-_EOF_
+echo "int main(){ char k; memset(&k,0,0); return 0; }" > conftest.c
$CC_TST $CFLAGS -o conftest conftest.c >/dev/null 2>/dev/null
status=$?
if [ $status -ne 0 ]; then
@@ -2613,7 +2610,6 @@
# Check for directory traversal libraries.
echon 'Check for directory traversal libraries (ndir, dirent, bsd, ...)...'
cat > conftest.c << _EOF_
-#include <dirent.h>
int main() { return closedir(opendir(".")); }
_EOF_
$CC_TST $CFLAGS -o conftest conftest.c >/dev/null 2>/dev/null
@@ -2642,10 +2638,7 @@
# Check for readlink().
# - Dynix/ptx 1.3 needed this.
echon 'Check for readlink()...'
-cat > conftest.c << _EOF_
-#include <unistd.h>
-int main(){ return readlink(); }
-_EOF_
+echo "int main(){ return readlink(); }" > conftest.c
$CC_TST $CFLAGS -o conftest conftest.c >/dev/null 2>/dev/null
status=$?
if [ $status -eq 0 ]; then
--- zipnote.c 2024-12-11 19:00:49.903326910 -0800
+++ zipnote.c.bak 2024-12-11 19:00:32.498833000 -0800
@@ -661,7 +661,7 @@
if ((r = zipcopy(z)) != ZE_OK)
ziperr(r, "was copying an entry");
}
- fclose(in_file);
+ fclose(x);
/* Write central directory and end of central directory with new comments */
if ((c = zftello(y)) == (zoff_t)-1) /* get start of central */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment