1 /*
2    Copyright (C) Andrew Tridgell 1998
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 
19 #define RZIP_MAJOR_VERSION 2
20 #define RZIP_MINOR_VERSION 1
21 
22 #define NUM_STREAMS 2
23 
24 #define _GNU_SOURCE
25 
26 #include "config.h"
27 
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <stddef.h>
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <netinet/in.h>
36 
37 #ifdef HAVE_STRING_H
38 #include <string.h>
39 #endif
40 
41 #ifdef HAVE_MALLOC_H
42 #include <malloc.h>
43 #endif
44 
45 #include <fcntl.h>
46 #include <sys/stat.h>
47 
48 #ifdef HAVE_CTYPE_H
49 #include <ctype.h>
50 #endif
51 #include <errno.h>
52 #include <sys/mman.h>
53 
54 #ifndef uchar
55 #define uchar unsigned char
56 #endif
57 
58 #ifndef int32
59 #if (SIZEOF_INT == 4)
60 #define int32 int
61 #elif (SIZEOF_LONG == 4)
62 #define int32 long
63 #elif (SIZEOF_SHORT == 4)
64 #define int32 short
65 #endif
66 #endif
67 
68 #ifndef int16
69 #if (SIZEOF_INT == 2)
70 #define int16 int
71 #elif (SIZEOF_SHORT == 2)
72 #define int16 short
73 #endif
74 #endif
75 
76 #ifndef uint32
77 #define uint32 unsigned int32
78 #endif
79 
80 #ifndef uint16
81 #define uint16 unsigned int16
82 #endif
83 
84 #ifndef MIN
85 #define MIN(a,b) ((a)<(b)?(a):(b))
86 #endif
87 
88 #ifndef MAX
89 #define MAX(a,b) ((a)>(b)?(a):(b))
90 #endif
91 
92 #if !HAVE_STRERROR
93 extern char *sys_errlist[];
94 #define strerror(i) sys_errlist[i]
95 #endif
96 
97 #ifndef HAVE_ERRNO_DECL
98 extern int errno;
99 #endif
100 
101 
102 #define FLAG_SHOW_PROGRESS 2
103 #define FLAG_KEEP_FILES 4
104 #define FLAG_TEST_ONLY 8
105 #define FLAG_FORCE_REPLACE 16
106 #define FLAG_DECOMPRESS 32
107 
108 
109 struct rzip_control {
110 	const char *infile, *outname;
111 	char *outfile;
112 	const char *suffix;
113 	unsigned compression_level;
114 	unsigned flags;
115 	unsigned verbosity;
116 };
117 
118 void fatal(const char *format, ...);
119 void err_msg(const char *format, ...);
120 off_t runzip_fd(int fd_in, int fd_out, int fd_hist, off_t expected_size);
121 void rzip_fd(struct rzip_control *control, int fd_in, int fd_out);
122 void *open_stream_out(int f, int n, int bzip_level);
123 void *open_stream_in(int f, int n);
124 int write_stream(void *ss, int stream, uchar *p, int len);
125 int read_stream(void *ss, int stream, uchar *p, int len);
126 int close_stream_out(void *ss);
127 int close_stream_in(void *ss);
128 void *Realloc(void *p, int size);
129 uint32 crc32_buffer(const uchar *buf, int n, uint32 crc);
130