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
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
*****************************************************************************/
#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) {
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");
#ifndef _BITSTREAM_H
#define _BITSTREAM_H
-#include "stdint.h"
+#include <stdint.h>
/* Input bitstream. */
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);
*****************************************************************************/
#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) {
#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. */
* @file inflate.c
*****************************************************************************/
#include <assert.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "huffman.h"
#include "lib.h"
#include "lz77.h"
-#include "stdint.h"
#include "tables.h"
#include "unzip.h"
uint16_t ebits;
int litlen, distsym;
-
-#ifndef NO_LONG_LONG
uint64_t used_tot;
-#endif
for (;;) {
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;
} 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;
}
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;
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;
#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"
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) {
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);
* @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) {
}
-#ifdef NO_LONG_LONG
- inc = 4;
-#else
inc = 8;
-#endif
-
i = 0;
do {
#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);
+++ /dev/null
-/******************************************************************************
- * @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 */
#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];
*****************************************************************************/
#include <assert.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 "tables.h"
#include "unzip.h"
#include "vector.h"
#ifndef _UNZIP_H
#define _UNZIP_H
-#include "stdint.h"
+#include <stdint.h>
#include "vector.h"
struct unzip_state {