OLD | NEW |
1 /////////////////////////////////////////////////////////////////////////////// | 1 /////////////////////////////////////////////////////////////////////////////// |
2 // | 2 // |
3 /// \file coder.c | 3 /// \file coder.c |
4 /// \brief Compresses or uncompresses a file | 4 /// \brief Compresses or uncompresses a file |
5 // | 5 // |
6 // Author: Lasse Collin | 6 // Author: Lasse Collin |
7 // | 7 // |
8 // This file has been put into the public domain. | 8 // This file has been put into the public domain. |
9 // You can do whatever you want with this file. | 9 // You can do whatever you want with this file. |
10 // | 10 // |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 return; | 279 return; |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 /// Return true if the data in in_buf seems to be in the .xz format. | 283 /// Return true if the data in in_buf seems to be in the .xz format. |
284 static bool | 284 static bool |
285 is_format_xz(void) | 285 is_format_xz(void) |
286 { | 286 { |
287 » return strm.avail_in >= 6 && memcmp(in_buf.u8, "\3757zXZ", 6) == 0; | 287 » // Specify the magic as hex to be compatible with EBCDIC systems. |
| 288 » static const uint8_t magic[6] = { 0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00 }; |
| 289 » return strm.avail_in >= sizeof(magic) |
| 290 » » » && memcmp(in_buf.u8, magic, sizeof(magic)) == 0; |
288 } | 291 } |
289 | 292 |
290 | 293 |
291 /// Return true if the data in in_buf seems to be in the .lzma format. | 294 /// Return true if the data in in_buf seems to be in the .lzma format. |
292 static bool | 295 static bool |
293 is_format_lzma(void) | 296 is_format_lzma(void) |
294 { | 297 { |
295 // The .lzma header is 13 bytes. | 298 // The .lzma header is 13 bytes. |
296 if (strm.avail_in < 13) | 299 if (strm.avail_in < 13) |
297 return false; | 300 return false; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 } | 657 } |
655 } | 658 } |
656 } | 659 } |
657 | 660 |
658 // Close the file pair. It needs to know if coding was successful to | 661 // Close the file pair. It needs to know if coding was successful to |
659 // know if the source or target file should be unlinked. | 662 // know if the source or target file should be unlinked. |
660 io_close(pair, success); | 663 io_close(pair, success); |
661 | 664 |
662 return; | 665 return; |
663 } | 666 } |
OLD | NEW |