diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/simple.c | 13 | ||||
| -rw-r--r-- | src/stream.c | 20 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/simple.c b/src/simple.c index da79562..be92977 100644 --- a/src/simple.c +++ b/src/simple.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | static void | 12 | static void |
| 13 | usage(void) | 13 | usage(void) |
| 14 | { | 14 | { |
| 15 | (void) fprintf(stderr, "compress [-d] infile outfile\n"); | 15 | (void) fprintf(stderr, "simple [-d] infile outfile\n"); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | static void | 18 | static void |
| @@ -142,10 +142,19 @@ main(int argc, char *argv[]) | |||
| 142 | 142 | ||
| 143 | if ( argc != 2 ) { | 143 | if ( argc != 2 ) { |
| 144 | usage(); | 144 | usage(); |
| 145 | return EXIT_FAILURE; | ||
| 146 | } | ||
| 147 | |||
| 148 | FILE *in_file = fopen(argv[0], "rb"); | ||
| 149 | if ( in_file == NULL ) { | ||
| 150 | error("fopen() on in_file failed"); | ||
| 145 | } | 151 | } |
| 146 | 152 | ||
| 147 | FILE *in_file = fopen(argv[0], "rb"); | ||
| 148 | FILE *out_file = fopen(argv[1], "wb"); | 153 | FILE *out_file = fopen(argv[1], "wb"); |
| 154 | if ( out_file == NULL ) { | ||
| 155 | (void) fclose(in_file); | ||
| 156 | error("fopen() on out_file failed"); | ||
| 157 | } | ||
| 149 | 158 | ||
| 150 | if ( !decompress ) { | 159 | if ( !decompress ) { |
| 151 | do_compress(in_file, out_file, compress_level); | 160 | do_compress(in_file, out_file, compress_level); |
diff --git a/src/stream.c b/src/stream.c index 286f41a..c6d2d35 100644 --- a/src/stream.c +++ b/src/stream.c | |||
| @@ -15,7 +15,14 @@ enum { BUFFER_SIZE = 8192 }; | |||
| 15 | static void | 15 | static void |
| 16 | usage(void) | 16 | usage(void) |
| 17 | { | 17 | { |
| 18 | (void) fprintf(stderr, "compress [-d] infile outfile\n"); | 18 | (void) fprintf(stderr, "stream [-d] infile outfile\n"); |
| 19 | } | ||
| 20 | |||
| 21 | static void | ||
| 22 | error(const char *msg) | ||
| 23 | { | ||
| 24 | perror(msg); | ||
| 25 | exit(EXIT_FAILURE); | ||
| 19 | } | 26 | } |
| 20 | 27 | ||
| 21 | static void | 28 | static void |
| @@ -162,10 +169,19 @@ main(int argc, char *argv[]) | |||
| 162 | 169 | ||
| 163 | if ( argc != 2 ) { | 170 | if ( argc != 2 ) { |
| 164 | usage(); | 171 | usage(); |
| 172 | return EXIT_FAILURE; | ||
| 173 | } | ||
| 174 | |||
| 175 | FILE *in_file = fopen(argv[0], "rb"); | ||
| 176 | if ( in_file == NULL ) { | ||
| 177 | error("fopen() on in_file failed"); | ||
| 165 | } | 178 | } |
| 166 | 179 | ||
| 167 | FILE *in_file = fopen(argv[0], "rb"); | ||
| 168 | FILE *out_file = fopen(argv[1], "wb"); | 180 | FILE *out_file = fopen(argv[1], "wb"); |
| 181 | if ( out_file == NULL ) { | ||
| 182 | (void) fclose(in_file); | ||
| 183 | error("fopen() on out_file failed"); | ||
| 184 | } | ||
| 169 | 185 | ||
| 170 | if ( !decompress ) { | 186 | if ( !decompress ) { |
| 171 | int error = do_compress(in_file, out_file, compress_level); | 187 | int error = do_compress(in_file, out_file, compress_level); |
