Removed C90 limitations and NO_LONG_LONG related stuff as even MinGW on Windows 2000...
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 19 Aug 2026 11:38:15 +0000 (12:38 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 19 Aug 2026 11:38:15 +0000 (12:38 +0100)
15 files changed:
Makefile.unix
Makefile.w32
bitstream.c
bitstream.h
huffman.c
huffman.h
inflate.c
lib.c
lib.h
lz77.c
lz77.h
stdint.h [deleted file]
tables.h
unzip.c
unzip.h

index 2c97be149deb595106ab5c1cf2c884a8a3563bd1..27f7fc3eb4be9a9a79744081d097f63a7a31c204 100644 (file)
@@ -5,7 +5,7 @@ SRCDIR              ?=  $(CURDIR)
 VPATH               :=  $(SRCDIR)
 
 CC                  :=  gcc
-CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -Wall -Werror -Wextra -std=c90
+CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -Wall -Werror -Wextra
 
 ifeq ($(OS), Windows_NT)
 all: unzip.exe
index 875d20ccd2d2195282c2b795c35245a83e57b8c5..ecbf0bfd000ac36c25b1e608c381ed04639d3bb3 100644 (file)
@@ -5,7 +5,7 @@ SRCDIR              ?=  $(CURDIR)
 VPATH               :=  $(SRCDIR)
 
 CC                  :=  gcc
-CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -Wall -Werror -Wextra -std=c90
+CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -Wall -Werror -Wextra
 
 all: unzip.exe
 
index 740afce296d1a464996af72f2f3e495a5b5d5b06..fe89586106550b4b1e87741d0ce28600b61fed48 100644 (file)
@@ -3,12 +3,12 @@
  *****************************************************************************/
 #include    <assert.h>
 #include    <limits.h>
+#include    <stdint.h>
 #include    <stdlib.h>
 #include    <string.h>
 
 #include    "bitstream.h"
 #include    "lib.h"
-#include    "stdint.h"
 
 int istream_init (istream_t *is, unsigned char *s, uint64_t n) {
 
@@ -51,13 +51,9 @@ unsigned char *istream_byte_align (istream_t *is) {
 uint64_t istream_bits (istream_t *is) {
 
     unsigned char *next;
-    uint64_t bits, i;
     
-#ifdef      NO_LONG_LONG
-    int cnt = 4;
-#else
+    uint64_t bits, i;
     int cnt = 8;
-#endif
     
     assert ((next = is->src + (is->bitpos / 8)) <= is->end && "cannot read past end of stream");
     
index 49c2fe4027eb25f756e8c591159944f0b0585b4c..e01fb81b63fceff8d7ed9643c18e8570a5810232 100644 (file)
@@ -4,7 +4,7 @@
 #ifndef     _BITSTREAM_H
 #define     _BITSTREAM_H
 
-#include    "stdint.h"
+#include    <stdint.h>
 
 /* Input bitstream. */
 typedef struct {
@@ -17,12 +17,7 @@ typedef struct {
 
 } istream_t;
 
-#ifdef      NO_LONG_LONG
-# define        ISTREAM_MIN_BITS        (32 - 7)
-#else
-# define        ISTREAM_MIN_BITS        (64 - 7)
-#endif
-
+#define         ISTREAM_MIN_BITS        (64 - 7)
 unsigned char *istream_byte_align (istream_t *is);
 
 int istream_init (istream_t *is, unsigned char *s, uint64_t n);
index b7ac1701099452c6cdd658787de9184f05590800..17fa3c9959701a8f294bc19319cf22d4225aa7cc 100644 (file)
--- a/huffman.c
+++ b/huffman.c
@@ -3,12 +3,12 @@
  *****************************************************************************/
 #include    <assert.h>
 #include    <limits.h>
+#include    <stdint.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 
 #include    "huffman.h"
 #include    "lib.h"
-#include    "stdint.h"
 #include    "tables.h"
 
 static uint16_t reverse16 (uint16_t x, int n) {
index 8a8c881159c36445ab07b11e685bde39291217e8..19ae230d544ac408602df879de07232b109bba88 100644 (file)
--- a/huffman.h
+++ b/huffman.h
@@ -4,7 +4,7 @@
 #ifndef     _HUFFMAN_H
 #define     _HUFFMAN_H
 
-#include    "stdint.h"
+#include    <stdint.h>
 
 #define     MAX_HUFFMAN_SYMBOLS                             288                 /* Deflate uses max 288 symbols. */
 #define     MAX_HUFFMAN_BITS                                16                  /* Implode uses max 16-bit codewords. */
index 69d3368da211d42876f795b582732f6f81ec7af7..27a23accaffc357b671f9d0eb2d828f0de1841f7 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -2,6 +2,7 @@
  * @file            inflate.c
  *****************************************************************************/
 #include    <assert.h>
+#include    <stdint.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 
@@ -9,7 +10,6 @@
 #include    "huffman.h"
 #include    "lib.h"
 #include    "lz77.h"
-#include    "stdint.h"
 #include    "tables.h"
 #include    "unzip.h"
 
@@ -58,10 +58,7 @@ static inf_stat_t inf_block (istream_t *is, FILE *outfile, uint64_t dst_cap, uin
     uint16_t ebits;
     
     int litlen, distsym;
-    
-#ifndef     NO_LONG_LONG
     uint64_t used_tot;
-#endif
     
     for (;;) {
     
@@ -71,34 +68,19 @@ static inf_stat_t inf_block (istream_t *is, FILE *outfile, uint64_t dst_cap, uin
         litlen = huffman_decode (litlen_dec, (uint16_t) bits, &used);
         /*printf ("litlen: %d\n", litlen);*/
         
-#ifdef      NO_LONG_LONG
-
-        if (!istream_advance (is, used)) {
-            return HWINF_ERR;
-        }
-
-#else
-
         bits >>= used;
         used_tot = used;
-
-#endif
         
         if (litlen < 0 || litlen > LITLEN_MAX) {
         
             /* Failed to decode, or invalid symbol. */
             return HWINF_ERR;
         
-        } else if (litlen <= UINT8_MAX) {
+        } else if (litlen <= (int) UINT8_MAX) {
         
-            /* Literal. */
-#ifndef     NO_LONG_LONG
-
             if (!istream_advance (is, used_tot)) {
                 return HWINF_ERR;
             }
-
-#endif
             
             if (*dst_pos == dst_cap) {
                 return HWINF_FULL;
@@ -113,15 +95,6 @@ static inf_stat_t inf_block (istream_t *is, FILE *outfile, uint64_t dst_cap, uin
         } else if (litlen == LITLEN_EOB) {
         
             /* End of block. */
-            
-#ifndef     NO_LONG_LONG
-
-            if (!istream_advance (is, used_tot)) {
-                return HWINF_ERR;
-            }
-
-#endif
-        
             return HWINF_OK;
         
         }
@@ -133,48 +106,18 @@ static inf_stat_t inf_block (istream_t *is, FILE *outfile, uint64_t dst_cap, uin
         
         if ((ebits = litlen_tbl[litlen - LITLEN_TBL_OFFSET].ebits) != 0) {
         
-#ifdef      NO_LONG_LONG
-            bits = istream_bits (is);
-#endif
-            
             len += lsb (bits, ebits);
             
-#ifdef      NO_LONG_LONG
-
-            if (!istream_advance (is, ebits)) {
-                return HWINF_ERR;
-            }
-
-#else
-
             bits >>= ebits;
             used_tot += ebits;
-
-#endif
         
         }
         
         assert (len >= MIN_LEN && len <= MAX_LEN);
-        
-        /* Get the distance. */
-#ifdef      NO_LONG_LONG
-        bits = istream_bits (is);
-#endif
-        
         distsym = huffman_decode (dist_dec, (uint16_t) bits, &used);
         
-#ifdef      NO_LONG_LONG
-
-        if (!istream_advance (is, used)) {
-            return HWINF_ERR;
-        }
-
-#else
-
         bits >>= used;
         used_tot += used;
-
-#endif
         
         if (distsym < 0 || distsym > DISTSYM_MAX) {
             return HWINF_ERR;
@@ -184,49 +127,25 @@ static inf_stat_t inf_block (istream_t *is, FILE *outfile, uint64_t dst_cap, uin
         
         if ((ebits = dist_tbl[distsym].ebits) != 0) {
         
-#ifdef      NO_LONG_LONG
-            bits = istream_bits (is);
-#endif
-        
             dist += lsb (bits, ebits);
-            
-#ifdef      NO_LONG_LONG
-
-            if (!istream_advance (is, ebits)) {
-                return HWINF_ERR;
-            }
-
-#else
-
             bits >>= ebits;
             used_tot += ebits;
-
-#endif
         
         }
         
         assert (dist >= MIN_DISTANCE && dist <= MAX_DISTANCE);
-        
-#ifndef      NO_LONG_LONG
-
         assert (used_tot <= ISTREAM_MIN_BITS);
         
         if (!istream_advance (is, used_tot)) {
             return HWINF_ERR;
         }
-
-#endif
         
         /* Bounds check and output the backref. */
         if (dist > *dst_pos) {
             return HWINF_ERR;
         }
         
-#ifdef      NO_LONG_LONG
-        if (round_up (len, 4) <= dst_cap - *dst_pos) {
-#else
         if (round_up (len, 8) <= dst_cap - *dst_pos) {
-#endif
         
             if (lz77_output_backref64 (outfile, *dst_pos, dist, len)) {
                 return HWINF_ERR;
diff --git a/lib.c b/lib.c
index 8a1a9984edfd758b15ec6c0d2d4f00690e8d9d9a..ce3d3c695ad5e740af878c67b53752b1cb0ee5c0 100755 (executable)
--- a/lib.c
+++ b/lib.c
@@ -4,13 +4,13 @@
 #include    <assert.h>
 #include    <ctype.h>
 #include    <limits.h>
+#include    <stdint.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <string.h>
 
 #include    "lib.h"
 #include    "report.h"
-#include    "stdint.h"
 #include    "unzip.h"
 #include    "vector.h"
 
@@ -145,18 +145,9 @@ uint64_t array_to_integer (unsigned char *arr, int size, int bigendian) {
 
 int lsb (uint64_t x, uint64_t n) {
 
-#ifdef      NO_LONG_LONG
-
-    assert (n <= 31);
-    return x & (((uint32_t) 1 << n) - 1);
-
-#else
-
     assert (n <= 63);
     return x & (((uint64_t) 1 << n) - 1);
 
-#endif
-
 }
 
 uint64_t round_up (uint64_t x, uint64_t m) {
diff --git a/lib.h b/lib.h
index be5d5d5d236bceb68ca2efadbb5d9f6c74774818..e80c091b931477811ab27db602c25fe0168798d4 100755 (executable)
--- a/lib.h
+++ b/lib.h
@@ -12,7 +12,7 @@ void *xrealloc (void *ptr, unsigned long size);
 
 void parse_args (int argc, char **argv, int optind);
 
-#include    "stdint.h"
+#include    <stdint.h>
 int lsb (uint64_t x, uint64_t n);
 
 uint64_t array_to_integer (unsigned char *arr, int size, int bigendian);
diff --git a/lz77.c b/lz77.c
index 265b4c23df5c311ac6ba023044bde50e7f5564b9..37c29ae7b12cbe4daf6bf0262d2ac4b7d0752aab 100644 (file)
--- a/lz77.c
+++ b/lz77.c
@@ -2,11 +2,11 @@
  * @file            lz77.c
  *****************************************************************************/
 #include    <assert.h>
+#include    <stdint.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 
 #include    "lz77.h"
-#include    "stdint.h"
 
 int lz77_output_lit (FILE *fp, uint64_t dst_pos, unsigned char lit) {
 
@@ -69,12 +69,7 @@ int lz77_output_backref64 (FILE *fp, uint64_t dst_pos, uint64_t dist, uint64_t l
     
     }
     
-#ifdef      NO_LONG_LONG
-    inc = 4;
-#else
     inc = 8;
-#endif
-    
     i = 0;
     
     do {
diff --git a/lz77.h b/lz77.h
index e7349e717a6854bc2e097e1b29574c0cff679887..a66632ef55c2607216058c3cd2358d57d60213b0 100644 (file)
--- a/lz77.h
+++ b/lz77.h
@@ -4,9 +4,9 @@
 #ifndef     _LZ77_H
 #define     _LZ77_H
 
-#include    "stdint.h"
-
+#include    <stdint.h>
 #include    <stdio.h>
+
 int lz77_output_lit (FILE *fp, uint64_t dst_pos, unsigned char lit);
 int lz77_output_backref (FILE *fp, uint64_t dst_pos, uint64_t dist, uint64_t len);
 int lz77_output_backref64 (FILE *fp, uint64_t dst_pos, uint64_t dist, uint64_t len);
diff --git a/stdint.h b/stdint.h
deleted file mode 100644 (file)
index 4a5e839..0000000
--- a/stdint.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/******************************************************************************
- * @file            stdint.h
- *****************************************************************************/
-#ifndef     _STDINT_H_INCLUDED
-#ifndef     _STDINT_H
-#ifndef     _STDINT_H_
-
-#define     _STDINT_H_INCLUDED
-#define     _STDINT_H
-#define     _STDINT_H_
-
-#include    <limits.h>
-
-/* Add all data types (even though we don't use them) as the project seems to fail to build on some systems. */
-typedef     signed char                 int8_t;
-typedef     unsigned char               uint8_t;
-
-typedef     signed short                int16_t;
-typedef     unsigned short              uint16_t;
-
-#if     INT_MAX > 32767
-typedef     signed int                  int32_t;
-typedef     unsigned int                uint32_t;
-#else
-typedef     signed long                 int32_t;
-typedef     unsigned long               uint32_t;
-#endif
-
-#ifndef     _INT64_T
-#define     _INT64_T
-#if     defined (NO_LONG_LONG) || ULONG_MAX > 4294967295UL
-typedef     signed long                 int64_t;
-#else
-typedef     signed long long            int64_t;
-#endif
-#endif      /* _INT64_T */
-
-#ifndef     _UINT64_T
-#define     _UINT64_T
-#if     defined (NO_LONG_LONG) || ULONG_MAX > 4294967295UL
-typedef     unsigned long               uint64_t;
-#else
-typedef     unsigned long long          uint64_t;
-#endif
-#endif      /* _UINT64_T */
-
-#define     UINT8_MAX                   0xff
-
-#endif      /* _STDINT_H_ */
-#endif      /* _STDINT_H */
-#endif      /* _STDINT_H_INCLUDED */
index d751a7422f698525256784a0686a50c507fca9bf..701a7c45b337783b61329313f476f412b200c3a7 100644 (file)
--- a/tables.h
+++ b/tables.h
@@ -4,7 +4,7 @@
 #ifndef     _TABLES_H
 #define     _TABLES_H
 
-#include    "stdint.h"
+#include    <stdint.h>
 
 /* Element x contains the value of x with the bits in reverse order. */
 extern const uint8_t reverse8_tbl[UINT8_MAX + 1];
diff --git a/unzip.c b/unzip.c
index 8650ff2132c5cb10a30d6b6c8350816537346144..1702ca785a2d9255c35b89b4110297c4a264c560 100755 (executable)
--- a/unzip.c
+++ b/unzip.c
@@ -3,6 +3,7 @@
  *****************************************************************************/
 #include    <assert.h>
 #include    <limits.h>
+#include    <stdint.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <string.h>
@@ -10,7 +11,6 @@
 
 #include    "lib.h"
 #include    "report.h"
-#include    "stdint.h"
 #include    "tables.h"
 #include    "unzip.h"
 #include    "vector.h"
diff --git a/unzip.h b/unzip.h
index e1757f8985f7172de28e28696c5c30313e790715..e1b692a9ca8a61c956469293f24acfa705db480e 100755 (executable)
--- a/unzip.h
+++ b/unzip.h
@@ -4,7 +4,7 @@
 #ifndef     _UNZIP_H
 #define     _UNZIP_H
 
-#include    "stdint.h"
+#include    <stdint.h>
 #include    "vector.h"
 
 struct unzip_state {