filerw.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 RTGUI_USING_DFS_FILERW
  17. #ifdef _WIN32_NATIVE
  18. #pragma warning(disable: 4996)
  19. #include <fcntl.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <io.h>
  23. #else
  24. #include <dfs_posix.h>
  25. #endif
  26. #endif
  27. #include <rtgui/rtgui.h>
  28. #define RTGUI_FILE_SEEK_SET 0
  29. #define RTGUI_FILE_SEEK_CUR 1
  30. #define RTGUI_FILE_SEEK_END 2
  31. struct rtgui_filerw
  32. {
  33. int (*seek)(struct rtgui_filerw *context, rt_off_t offset, int whence);
  34. int (*read)(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
  35. int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
  36. int (*tell)(struct rtgui_filerw *context);
  37. int (*eof)(struct rtgui_filerw *context);
  38. int (*close)(struct rtgui_filerw *context);
  39. };
  40. typedef struct rtgui_filerw rtgui_filerw_t;
  41. struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode);
  42. struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size);
  43. int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence);
  44. int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
  45. int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
  46. int rtgui_filerw_tell(struct rtgui_filerw *context);
  47. int rtgui_filerw_eof(struct rtgui_filerw *context);
  48. int rtgui_filerw_close(struct rtgui_filerw *context);
  49. int rtgui_filerw_unlink(const char *filename);
  50. /* get memory data from filerw memory object */
  51. const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context);
  52. #endif