From: Robert Pengelly Date: Wed, 19 Aug 2026 11:38:15 +0000 (+0100) Subject: Removed C90 limitations and NO_LONG_LONG related stuff as even MinGW on Windows 2000... X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=21006e5683ccb20bfc42420fdd1179ff1fdf9f2e;p=unzip.git Removed C90 limitations and NO_LONG_LONG related stuff as even MinGW on Windows 2000 works --- diff --git a/Makefile.unix b/Makefile.unix index 2c97be1..27f7fc3 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -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 diff --git a/Makefile.w32 b/Makefile.w32 index 875d20c..ecbf0bf 100644 --- a/Makefile.w32 +++ b/Makefile.w32 @@ -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 diff --git a/bitstream.c b/bitstream.c index 740afce..fe89586 100644 --- a/bitstream.c +++ b/bitstream.c @@ -3,12 +3,12 @@ *****************************************************************************/ #include #include +#include #include #include #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"); diff --git a/bitstream.h b/bitstream.h index 49c2fe4..e01fb81 100644 --- a/bitstream.h +++ b/bitstream.h @@ -4,7 +4,7 @@ #ifndef _BITSTREAM_H #define _BITSTREAM_H -#include "stdint.h" +#include /* 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); diff --git a/huffman.c b/huffman.c index b7ac170..17fa3c9 100644 --- a/huffman.c +++ b/huffman.c @@ -3,12 +3,12 @@ *****************************************************************************/ #include #include +#include #include #include #include "huffman.h" #include "lib.h" -#include "stdint.h" #include "tables.h" static uint16_t reverse16 (uint16_t x, int n) { diff --git a/huffman.h b/huffman.h index 8a8c881..19ae230 100644 --- a/huffman.h +++ b/huffman.h @@ -4,7 +4,7 @@ #ifndef _HUFFMAN_H #define _HUFFMAN_H -#include "stdint.h" +#include #define MAX_HUFFMAN_SYMBOLS 288 /* Deflate uses max 288 symbols. */ #define MAX_HUFFMAN_BITS 16 /* Implode uses max 16-bit codewords. */ diff --git a/inflate.c b/inflate.c index 69d3368..27a23ac 100644 --- a/inflate.c +++ b/inflate.c @@ -2,6 +2,7 @@ * @file inflate.c *****************************************************************************/ #include +#include #include #include @@ -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 8a1a998..ce3d3c6 100755 --- a/lib.c +++ b/lib.c @@ -4,13 +4,13 @@ #include #include #include +#include #include #include #include #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 be5d5d5..e80c091 100755 --- 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 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 265b4c2..37c29ae 100644 --- a/lz77.c +++ b/lz77.c @@ -2,11 +2,11 @@ * @file lz77.c *****************************************************************************/ #include +#include #include #include #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 e7349e7..a66632e 100644 --- a/lz77.h +++ b/lz77.h @@ -4,9 +4,9 @@ #ifndef _LZ77_H #define _LZ77_H -#include "stdint.h" - +#include #include + 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 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 - -/* 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 */ diff --git a/tables.h b/tables.h index d751a74..701a7c4 100644 --- a/tables.h +++ b/tables.h @@ -4,7 +4,7 @@ #ifndef _TABLES_H #define _TABLES_H -#include "stdint.h" +#include /* 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 8650ff2..1702ca7 100755 --- a/unzip.c +++ b/unzip.c @@ -3,6 +3,7 @@ *****************************************************************************/ #include #include +#include #include #include #include @@ -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 e1757f8..e1b692a 100755 --- a/unzip.h +++ b/unzip.h @@ -4,7 +4,7 @@ #ifndef _UNZIP_H #define _UNZIP_H -#include "stdint.h" +#include #include "vector.h" struct unzip_state {