diff options
Diffstat (limited to 'minigzip.c')
-rw-r--r-- | minigzip.c | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -19,9 +19,9 @@ | |||
19 | #include "zlib.h" | 19 | #include "zlib.h" |
20 | 20 | ||
21 | #ifndef __GO32__ | 21 | #ifndef __GO32__ |
22 | extern void exit __P((int)); | 22 | extern void exit OF((int)); |
23 | #endif | 23 | #endif |
24 | extern int unlink __P((const char *)); | 24 | extern int unlink OF((const char *)); |
25 | 25 | ||
26 | #ifdef STDC | 26 | #ifdef STDC |
27 | # include <string.h> | 27 | # include <string.h> |
@@ -35,6 +35,13 @@ extern int unlink __P((const char *)); | |||
35 | # define SET_BINARY_MODE(file) | 35 | # define SET_BINARY_MODE(file) |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #ifdef VMS | ||
39 | # define GZ_SUFFIX "-gz" | ||
40 | #else | ||
41 | # define GZ_SUFFIX ".gz" | ||
42 | #endif | ||
43 | #define SUFFIX_LEN sizeof(GZ_SUFFIX) | ||
44 | |||
38 | #define BUFLEN 4096 | 45 | #define BUFLEN 4096 |
39 | #define MAX_NAME_LEN 1024 | 46 | #define MAX_NAME_LEN 1024 |
40 | 47 | ||
@@ -46,12 +53,12 @@ extern int unlink __P((const char *)); | |||
46 | 53 | ||
47 | char *prog; | 54 | char *prog; |
48 | 55 | ||
49 | void error __P((char *msg)); | 56 | void error OF((char *msg)); |
50 | void gz_compress __P((FILE *in, gzFile out)); | 57 | void gz_compress OF((FILE *in, gzFile out)); |
51 | void gz_uncompress __P((gzFile in, FILE *out)); | 58 | void gz_uncompress OF((gzFile in, FILE *out)); |
52 | void file_compress __P((char *file)); | 59 | void file_compress OF((char *file)); |
53 | void file_uncompress __P((char *file)); | 60 | void file_uncompress OF((char *file)); |
54 | void main __P((int argc, char *argv[])); | 61 | int main OF((int argc, char *argv[])); |
55 | 62 | ||
56 | /* =========================================================================== | 63 | /* =========================================================================== |
57 | * Display error message and exit | 64 | * Display error message and exit |
@@ -124,14 +131,14 @@ void file_compress(file) | |||
124 | gzFile out; | 131 | gzFile out; |
125 | 132 | ||
126 | strcpy(outfile, file); | 133 | strcpy(outfile, file); |
127 | strcat(outfile, ".gz"); | 134 | strcat(outfile, GZ_SUFFIX); |
128 | 135 | ||
129 | in = fopen(file, "rb"); | 136 | in = fopen(file, "rb"); |
130 | if (in == NULL) { | 137 | if (in == NULL) { |
131 | perror(file); | 138 | perror(file); |
132 | exit(1); | 139 | exit(1); |
133 | } | 140 | } |
134 | out = gzopen(outfile, "wb"); | 141 | out = gzopen(outfile, "wb"); /* use "wb9" for maximal compression */ |
135 | if (out == NULL) { | 142 | if (out == NULL) { |
136 | fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); | 143 | fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); |
137 | exit(1); | 144 | exit(1); |
@@ -156,14 +163,14 @@ void file_uncompress(file) | |||
156 | 163 | ||
157 | strcpy(buf, file); | 164 | strcpy(buf, file); |
158 | 165 | ||
159 | if (len > 3 && strcmp(file+len-3, ".gz") == 0) { | 166 | if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { |
160 | infile = file; | 167 | infile = file; |
161 | outfile = buf; | 168 | outfile = buf; |
162 | outfile[len-3] = '\0'; | 169 | outfile[len-3] = '\0'; |
163 | } else { | 170 | } else { |
164 | outfile = file; | 171 | outfile = file; |
165 | infile = buf; | 172 | infile = buf; |
166 | strcat(infile, ".gz"); | 173 | strcat(infile, GZ_SUFFIX); |
167 | } | 174 | } |
168 | in = gzopen(infile, "rb"); | 175 | in = gzopen(infile, "rb"); |
169 | if (in == NULL) { | 176 | if (in == NULL) { |
@@ -186,7 +193,7 @@ void file_uncompress(file) | |||
186 | * Usage: minigzip [-d] [files...] | 193 | * Usage: minigzip [-d] [files...] |
187 | */ | 194 | */ |
188 | 195 | ||
189 | void main(argc, argv) | 196 | int main(argc, argv) |
190 | int argc; | 197 | int argc; |
191 | char *argv[]; | 198 | char *argv[]; |
192 | { | 199 | { |
@@ -210,7 +217,7 @@ void main(argc, argv) | |||
210 | if (file == NULL) error("can't gzdopen stdin"); | 217 | if (file == NULL) error("can't gzdopen stdin"); |
211 | gz_uncompress(file, stdout); | 218 | gz_uncompress(file, stdout); |
212 | } else { | 219 | } else { |
213 | file = gzdopen(fileno(stdout), "wb"); | 220 | file = gzdopen(fileno(stdout), "wb"); /* "wb9" for max compr. */ |
214 | if (file == NULL) error("can't gzdopen stdout"); | 221 | if (file == NULL) error("can't gzdopen stdout"); |
215 | gz_compress(stdin, file); | 222 | gz_compress(stdin, file); |
216 | } | 223 | } |
@@ -224,4 +231,5 @@ void main(argc, argv) | |||
224 | } while (argv++, --argc); | 231 | } while (argv++, --argc); |
225 | } | 232 | } |
226 | exit(0); | 233 | exit(0); |
234 | return 0; /* to avoid warning */ | ||
227 | } | 235 | } |