buf_reader.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright 2020 NXP
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining
  9. * a copy of this software and associated documentation files (the
  10. * 'Software'), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sub license, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject
  14. * to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial
  18. * portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  21. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. * IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
  24. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. *****************************************************************************/
  29. /* Bufferred reader interface */
  30. #ifndef _BUFFERRED_READER_
  31. #define _BUFFERRED_READER_
  32. typedef struct buffered_reader {
  33. char *data_buf;
  34. int size;
  35. int index;
  36. int is_valid;
  37. } bufferred_reader_t;
  38. #define E_BUF_IO_OUT_OF_MEMORY -10
  39. #define E_BUF_IO_READ_ERROR -11
  40. #define E_BUF_INVALID_HANDLE -12
  41. #define E_BUF_IO_INVALID_PARAMETERS -13
  42. int is_buffered_handle_valid(bufferred_reader_t *fd);
  43. int bufferred_fopen(bufferred_reader_t *fd, char *buf, int size);
  44. int bufferred_ftell(bufferred_reader_t *fd);
  45. int bufferred_fread(
  46. void *ptr,
  47. int size,
  48. int nmemb,
  49. bufferred_reader_t *fd
  50. );
  51. int bufferred_fseek(
  52. bufferred_reader_t *fd,
  53. int offset,
  54. int direction
  55. );
  56. int bufferred_fclose(bufferred_reader_t *fd);
  57. char *bufferred_fgets(char* buff, int len, bufferred_reader_t *fd);
  58. #endif //!_BUFFERRED_READER_