OLD | NEW |
1 /*- | 1 /*- |
2 * Copyright 2003-2005 Colin Percival | 2 * Copyright 2003-2005 Colin Percival |
3 * All rights reserved | 3 * All rights reserved |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted providing that the following conditions | 6 * modification, are permitted providing that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 xzf->ls.next_in = xzf->in; | 187 xzf->ls.next_in = xzf->in; |
188 xzf->ls.avail_in = fread(xzf->in, 1, BUFSIZ, | 188 xzf->ls.avail_in = fread(xzf->in, 1, BUFSIZ, |
189 xzf->f); | 189 xzf->f); |
190 if (ferror(xzf->f)) { | 190 if (ferror(xzf->f)) { |
191 /* Map I/O errors to LZMA_STREAM_END. */ | 191 /* Map I/O errors to LZMA_STREAM_END. */ |
192 xzf->err = LZMA_STREAM_END; | 192 xzf->err = LZMA_STREAM_END; |
193 if (err) *err = xzf->err; | 193 if (err) *err = xzf->err; |
194 return 0; | 194 return 0; |
195 } else if (feof(xzf->f)) { | 195 } else if (feof(xzf->f)) { |
196 xzf->eof = 1; | 196 xzf->eof = 1; |
197 /* LZMA_FINISH is not critical because | |
198 * LZMA_CONCATENATED is not in use. */ | |
199 action = LZMA_FINISH; | |
200 } | 197 } |
201 } | 198 } |
202 | 199 |
203 /* Use the full output buffer. */ | 200 /* Use the full output buffer. */ |
204 xzf->ls.next_out = xzf->out; | 201 xzf->ls.next_out = xzf->out; |
205 xzf->ls.avail_out = BUFSIZ; | 202 xzf->ls.avail_out = BUFSIZ; |
206 | 203 |
207 /* There must be something to decode. */ | 204 /* There must be something to decode. */ |
208 if (xzf->ls.avail_in == 0) { | 205 if (xzf->ls.avail_in == 0) { |
209 xzf->err = LZMA_BUF_ERROR; | 206 xzf->err = LZMA_BUF_ERROR; |
210 if (err) *err = xzf->err; | 207 if (err) *err = xzf->err; |
211 return 0; | 208 return 0; |
212 } | 209 } |
213 | 210 |
| 211 /* LZMA_FINISH is not critical because |
| 212 * LZMA_CONCATENATED is not in use. */ |
| 213 if (xzf->eof) |
| 214 action = LZMA_FINISH; |
| 215 |
214 /* Run the decoder. */ | 216 /* Run the decoder. */ |
215 xzf->err = lzma_code(&xzf->ls, action); | 217 xzf->err = lzma_code(&xzf->ls, action); |
216 if (xzf->err == LZMA_STREAM_END) { | 218 if (xzf->err == LZMA_STREAM_END) { |
217 xzf->eof = 1; | 219 xzf->eof = 1; |
218 xzf->err = LZMA_OK; | 220 xzf->err = LZMA_OK; |
219 } else if (xzf->err != LZMA_OK) { | 221 } else if (xzf->err != LZMA_OK) { |
220 if (err) *err = xzf->err; | 222 if (err) *err = xzf->err; |
221 return 0; | 223 return 0; |
222 } | 224 } |
223 | 225 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 /* Write the new file */ | 526 /* Write the new file */ |
525 if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0644))<0) || | 527 if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0644))<0) || |
526 (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) | 528 (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) |
527 err(1,"open/write/close(%s)",argv[2]); | 529 err(1,"open/write/close(%s)",argv[2]); |
528 | 530 |
529 free(new); | 531 free(new); |
530 free(old); | 532 free(old); |
531 | 533 |
532 return 0; | 534 return 0; |
533 } | 535 } |
OLD | NEW |