| OLD | NEW |
| 1 /////////////////////////////////////////////////////////////////////////////// | 1 /////////////////////////////////////////////////////////////////////////////// |
| 2 // | 2 // |
| 3 /// \file alone_decoder.c | 3 /// \file alone_decoder.c |
| 4 /// \brief Decoder for LZMA_Alone files | 4 /// \brief Decoder for LZMA_Alone files |
| 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 14 matching lines...) Expand all Loading... |
| 25 SEQ_CODE, | 25 SEQ_CODE, |
| 26 } sequence; | 26 } sequence; |
| 27 | 27 |
| 28 size_t header_pos; | 28 size_t header_pos; |
| 29 uint8_t header[ALONE_HEADER_SIZE]; | 29 uint8_t header[ALONE_HEADER_SIZE]; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 | 32 |
| 33 static lzma_ret | 33 static lzma_ret |
| 34 alone_encode(lzma_coder *coder, | 34 alone_encode(lzma_coder *coder, |
| 35 » » lzma_allocator *allocator lzma_attribute((unused)), | 35 » » lzma_allocator *allocator lzma_attribute((__unused__)), |
| 36 const uint8_t *restrict in, size_t *restrict in_pos, | 36 const uint8_t *restrict in, size_t *restrict in_pos, |
| 37 size_t in_size, uint8_t *restrict out, | 37 size_t in_size, uint8_t *restrict out, |
| 38 size_t *restrict out_pos, size_t out_size, | 38 size_t *restrict out_pos, size_t out_size, |
| 39 lzma_action action) | 39 lzma_action action) |
| 40 { | 40 { |
| 41 while (*out_pos < out_size) | 41 while (*out_pos < out_size) |
| 42 switch (coder->sequence) { | 42 switch (coder->sequence) { |
| 43 case SEQ_HEADER: | 43 case SEQ_HEADER: |
| 44 lzma_bufcpy(coder->header, &coder->header_pos, | 44 lzma_bufcpy(coder->header, &coder->header_pos, |
| 45 ALONE_HEADER_SIZE, | 45 ALONE_HEADER_SIZE, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 // Encode the header: | 97 // Encode the header: |
| 98 // - Properties (1 byte) | 98 // - Properties (1 byte) |
| 99 if (lzma_lzma_lclppb_encode(options, next->coder->header)) | 99 if (lzma_lzma_lclppb_encode(options, next->coder->header)) |
| 100 return LZMA_OPTIONS_ERROR; | 100 return LZMA_OPTIONS_ERROR; |
| 101 | 101 |
| 102 // - Dictionary size (4 bytes) | 102 // - Dictionary size (4 bytes) |
| 103 if (options->dict_size < LZMA_DICT_SIZE_MIN) | 103 if (options->dict_size < LZMA_DICT_SIZE_MIN) |
| 104 return LZMA_OPTIONS_ERROR; | 104 return LZMA_OPTIONS_ERROR; |
| 105 | 105 |
| 106 » // Round up to to the next 2^n or 2^n + 2^(n - 1) depending on which | 106 » // Round up to the next 2^n or 2^n + 2^(n - 1) depending on which |
| 107 // one is the next unless it is UINT32_MAX. While the header would | 107 // one is the next unless it is UINT32_MAX. While the header would |
| 108 // allow any 32-bit integer, we do this to keep the decoder of liblzma | 108 // allow any 32-bit integer, we do this to keep the decoder of liblzma |
| 109 // accepting the resulting files. | 109 // accepting the resulting files. |
| 110 uint32_t d = options->dict_size - 1; | 110 uint32_t d = options->dict_size - 1; |
| 111 d |= d >> 2; | 111 d |= d >> 2; |
| 112 d |= d >> 3; | 112 d |= d >> 3; |
| 113 d |= d >> 4; | 113 d |= d >> 4; |
| 114 d |= d >> 8; | 114 d |= d >> 8; |
| 115 d |= d >> 16; | 115 d |= d >> 16; |
| 116 if (d != UINT32_MAX) | 116 if (d != UINT32_MAX) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 extern LZMA_API(lzma_ret) | 148 extern LZMA_API(lzma_ret) |
| 149 lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options) | 149 lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options) |
| 150 { | 150 { |
| 151 lzma_next_strm_init(alone_encoder_init, strm, options); | 151 lzma_next_strm_init(alone_encoder_init, strm, options); |
| 152 | 152 |
| 153 strm->internal->supported_actions[LZMA_RUN] = true; | 153 strm->internal->supported_actions[LZMA_RUN] = true; |
| 154 strm->internal->supported_actions[LZMA_FINISH] = true; | 154 strm->internal->supported_actions[LZMA_FINISH] = true; |
| 155 | 155 |
| 156 return LZMA_OK; | 156 return LZMA_OK; |
| 157 } | 157 } |
| OLD | NEW |