OLD | NEW |
1 /* | 1 /* |
2 * xz_pipe_decomp.c | 2 * xz_pipe_decomp.c |
3 * A simple example of pipe-only xz decompressor implementation. | 3 * A simple example of pipe-only xz decompressor implementation. |
4 * version: 2010-07-12 - by Daniel Mealha Cabrita | 4 * version: 2012-06-14 - by Daniel Mealha Cabrita |
5 * Not copyrighted -- provided to the public domain. | 5 * Not copyrighted -- provided to the public domain. |
6 * | 6 * |
7 * Compiling: | 7 * Compiling: |
8 * Link with liblzma. GCC example: | 8 * Link with liblzma. GCC example: |
9 * $ gcc -llzma xz_pipe_decomp.c -o xz_pipe_decomp | 9 * $ gcc -llzma xz_pipe_decomp.c -o xz_pipe_decomp |
10 * | 10 * |
11 * Usage example: | 11 * Usage example: |
12 * $ cat some_file.xz | ./xz_pipe_decomp > some_file | 12 * $ cat some_file.xz | ./xz_pipe_decomp > some_file |
13 */ | 13 */ |
14 | 14 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 out_len = OUT_BUF_MAX - strm.avail_out; | 94 out_len = OUT_BUF_MAX - strm.avail_out; |
95 fwrite (out_buf, 1, out_len, out_file); | 95 fwrite (out_buf, 1, out_len, out_file); |
96 if (ferror (out_file)) { | 96 if (ferror (out_file)) { |
97 out_finished = true; | 97 out_finished = true; |
98 ret = RET_ERROR_OUTPUT; | 98 ret = RET_ERROR_OUTPUT; |
99 } | 99 } |
100 } | 100 } |
101 } while (strm.avail_out == 0); | 101 } while (strm.avail_out == 0); |
102 } | 102 } |
103 | 103 |
| 104 /* Bug fix (2012-06-14): If no errors were detected, check |
| 105 that the last lzma_code() call returned LZMA_STREAM_END. |
| 106 If not, the file is probably truncated. */ |
| 107 if ((ret == RET_OK) && (ret_xz != LZMA_STREAM_END)) { |
| 108 fprintf (stderr, "Input truncated or corrupt\n"); |
| 109 ret = RET_ERROR_DECOMPRESSION; |
| 110 } |
| 111 |
104 lzma_end (&strm); | 112 lzma_end (&strm); |
105 return ret; | 113 return ret; |
106 } | 114 } |
107 | 115 |
108 int main () | 116 int main () |
109 { | 117 { |
110 int ret; | 118 int ret; |
111 | 119 |
112 ret = xz_decompress (stdin, stdout); | 120 ret = xz_decompress (stdin, stdout); |
113 return ret; | 121 return ret; |
114 } | 122 } |
115 | 123 |
OLD | NEW |