filerw.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * File : filerw.h
  3. * This file is part of RT-Thread GUI Engine
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2009-10-16 Bernard first version
  23. */
  24. #ifndef __RTGUI_FILERW_H__
  25. #define __RTGUI_FILERW_H__
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifdef RTGUI_USING_DFS_FILERW
  30. #ifdef _WIN32_NATIVE
  31. #pragma warning(disable: 4996)
  32. #include <fcntl.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <io.h>
  36. #else
  37. #include <dfs_posix.h>
  38. #endif
  39. #endif
  40. #include <rtgui/rtgui.h>
  41. #define RTGUI_FILE_SEEK_SET 0
  42. #define RTGUI_FILE_SEEK_CUR 1
  43. #define RTGUI_FILE_SEEK_END 2
  44. struct rtgui_filerw
  45. {
  46. int (*seek)(struct rtgui_filerw *context, rt_off_t offset, int whence);
  47. int (*read)(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
  48. int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
  49. int (*tell)(struct rtgui_filerw *context);
  50. int (*eof)(struct rtgui_filerw *context);
  51. int (*close)(struct rtgui_filerw *context);
  52. };
  53. typedef struct rtgui_filerw rtgui_filerw_t;
  54. struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode);
  55. struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size);
  56. int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence);
  57. int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
  58. int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
  59. int rtgui_filerw_tell(struct rtgui_filerw *context);
  60. int rtgui_filerw_eof(struct rtgui_filerw *context);
  61. int rtgui_filerw_close(struct rtgui_filerw *context);
  62. int rtgui_filerw_unlink(const char *filename);
  63. /* get memory data from filerw memory object */
  64. const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif