null_decoder.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright (c) 2011, 2012, Simon Howard
  3. Permission to use, copy, modify, and/or distribute this software
  4. for any purpose with or without fee is hereby granted, provided
  5. that the above copyright notice and this permission notice appear
  6. in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  8. WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  9. WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  10. AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  11. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. // Null decoder, for uncompressed files.
  17. #include <stdlib.h>
  18. #include <inttypes.h>
  19. #include "lha_decoder.h"
  20. #define BLOCK_READ_SIZE 1024
  21. typedef struct {
  22. LHADecoderCallback callback;
  23. void *callback_data;
  24. } LHANullDecoder;
  25. static int lha_null_init(void *data, LHADecoderCallback callback,
  26. void *callback_data)
  27. {
  28. LHANullDecoder *decoder = data;
  29. decoder->callback = callback;
  30. decoder->callback_data = callback_data;
  31. return 1;
  32. }
  33. static size_t lha_null_read(void *data, uint8_t *buf)
  34. {
  35. LHANullDecoder *decoder = data;
  36. return decoder->callback(buf, BLOCK_READ_SIZE, decoder->callback_data);
  37. }
  38. LHADecoderType lha_null_decoder = {
  39. lha_null_init,
  40. NULL,
  41. lha_null_read,
  42. sizeof(LHANullDecoder),
  43. BLOCK_READ_SIZE,
  44. 2048
  45. };