filerw.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * File : filerw.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #ifndef __RTGUI_FILERW_H__
  15. #define __RTGUI_FILERW_H__
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #ifdef RTGUI_USING_DFS_FILERW
  20. #ifdef _WIN32_NATIVE
  21. #pragma warning(disable: 4996)
  22. #include <fcntl.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <io.h>
  26. #else
  27. #include <dfs_posix.h>
  28. #endif
  29. #endif
  30. #include <rtgui/rtgui.h>
  31. #define RTGUI_FILE_SEEK_SET 0
  32. #define RTGUI_FILE_SEEK_CUR 1
  33. #define RTGUI_FILE_SEEK_END 2
  34. struct rtgui_filerw
  35. {
  36. int (*seek)(struct rtgui_filerw *context, rt_off_t offset, int whence);
  37. int (*read)(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
  38. int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
  39. int (*tell)(struct rtgui_filerw *context);
  40. int (*eof)(struct rtgui_filerw *context);
  41. int (*close)(struct rtgui_filerw *context);
  42. };
  43. typedef struct rtgui_filerw rtgui_filerw_t;
  44. struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode);
  45. struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size);
  46. int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence);
  47. int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
  48. int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
  49. int rtgui_filerw_tell(struct rtgui_filerw *context);
  50. int rtgui_filerw_eof(struct rtgui_filerw *context);
  51. int rtgui_filerw_close(struct rtgui_filerw *context);
  52. int rtgui_filerw_unlink(const char *filename);
  53. /* get memory data from filerw memory object */
  54. const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif