1
0

std_file.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef _STD_FILE_H
  2. #define _STD_FILE_H
  3. #include <bfc/platform/platform.h>
  4. #include "wasabi_std.h"
  5. #include <stdio.h>
  6. /* TODO:
  7. FEOF
  8. FFLUSH
  9. FGETPOS - maybe implement as just FTELL?
  10. FSETPOS - maybe implement as just FSEEK?
  11. FPUTS - no problems, look at FPRINTF implementation
  12. FSTAT (in conjunction with FILENO), only fill in _stat::st_size for now (via getFileSize)
  13. */
  14. #ifndef _NOSTUDIO
  15. // EXTC is used here as some .c files will use these functions
  16. #define NO_FILEREADERS false
  17. #ifdef _WIN32
  18. #define WF_READONLY_BINARY L"rb"
  19. #define WF_WRITE_TEXT L"wt"
  20. #define WF_WRITE_BINARY L"wb"
  21. #define WF_APPEND L"a"
  22. #define WF_APPEND_RW L"a+"
  23. #define OPEN_FAILED INVALID_HANDLE_VALUE
  24. #elif defined(__APPLE__)
  25. #define WF_READONLY_BINARY "r"
  26. #define WF_WRITE_TEXT "w"
  27. #define WF_WRITE_BINARY "w"
  28. #define WF_APPEND "a"
  29. #define WF_APPEND_RW "a+"
  30. #define OPEN_FAILED 0
  31. #endif
  32. #ifdef _WIN32
  33. typedef HANDLE OSFILETYPE;
  34. #else
  35. #error port me
  36. #endif
  37. OSFILETYPE WFOPEN(const wchar_t *filename, OSFNCSTR mode, bool useFileReaders = true);
  38. int FCLOSE(OSFILETYPE stream);
  39. int FSEEK(OSFILETYPE stream, long offset, int origin);
  40. uint64_t FTELL(OSFILETYPE stream);
  41. #undef FREAD // defined on Mac for some reason
  42. size_t FREAD(void *buffer, size_t size, size_t count, OSFILETYPE stream);
  43. #undef FWRITE // defined on Mac for some reason
  44. size_t FWRITE(const void *buffer, size_t size, size_t count, OSFILETYPE stream);
  45. //char *FGETS( char *string, int n, OSFILETYPE stream);
  46. //int FPRINTF(OSFILETYPE stream, const char *format , ...);
  47. uint64_t FGETSIZE(OSFILETYPE stream);
  48. const wchar_t *TMPNAM(wchar_t *string);
  49. OSFNCSTR TMPNAM2(wchar_t *string, int val);
  50. int FEXISTS(const char *filename); // return 1 if true, 0 if not, -1 if unknown
  51. int UNLINK(const wchar_t *filename); // return 1 on success, 0 on error
  52. int WACCESS(const wchar_t *filename, int mode);
  53. #ifdef __cplusplus
  54. // returns 1 on success, 0 on error, -1 if undoable deletes aren't supported
  55. int FDELETE(OSFNCSTR filename, int permanently=TRUE);
  56. #else
  57. int FDELETE(OSFNCSTR filename, int permanently);
  58. #endif
  59. // 1 on success, 0 on fail
  60. // can't move directories between volumes on win32
  61. int MOVEFILE(OSFNCSTR filename, OSFNCSTR destfilename);
  62. #ifdef __cplusplus
  63. namespace StdFile {
  64. #endif
  65. int resolveShortcut(OSFNCSTR filename, OSFNSTR destfilename, int maxbuf);
  66. #ifdef __cplusplus
  67. };
  68. #endif
  69. #ifdef WASABI_COMPILE_FILEREADER
  70. #ifndef REAL_STDIO
  71. #ifndef __APPLE__
  72. //#define fopen FOPEN
  73. //#define fclose FCLOSE
  74. //#define fseek FSEEK
  75. //#define ftell FTELL
  76. //#define fread FREAD
  77. //#define fwrite FWRITE
  78. //#define fgets FGETS
  79. //#define fprintf FPRINTF
  80. //#define unlink UNLINK
  81. //#define access ACCESS
  82. #endif
  83. #endif //real_stdio
  84. #endif //WASABI_COMPILE_FILEREADER
  85. #endif //_nostudio
  86. #endif