posix_compat.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. compatibility with posix APIs using AP_Filesystem
  15. */
  16. #pragma once
  17. #include <sys/types.h>
  18. #include <stdio.h>
  19. #include <stddef.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /*
  24. these are here to allow lua to build on HAL_ChibiOS
  25. */
  26. typedef struct apfs_file APFS_FILE;
  27. APFS_FILE *apfs_fopen(const char *pathname, const char *mode);
  28. int apfs_fprintf(APFS_FILE *stream, const char *format, ...);
  29. int apfs_fflush(APFS_FILE *stream);
  30. size_t apfs_fread(void *ptr, size_t size, size_t nmemb, APFS_FILE *stream);
  31. size_t apfs_fwrite(const void *ptr, size_t size, size_t nmemb, APFS_FILE *stream);
  32. int apfs_fputs(const char *s, APFS_FILE *stream);
  33. char *apfs_fgets(char *s, int size, APFS_FILE *stream);
  34. void apfs_clearerr(APFS_FILE *stream);
  35. int apfs_fseek(APFS_FILE *stream, long offset, int whence);
  36. int apfs_ferror(APFS_FILE *stream);
  37. int apfs_fclose(APFS_FILE *stream);
  38. APFS_FILE *apfs_tmpfile(void);
  39. int apfs_getc(APFS_FILE *stream);
  40. int apfs_ungetc(int c, APFS_FILE *stream);
  41. int apfs_feof(APFS_FILE *stream);
  42. long apfs_ftell(APFS_FILE *stream);
  43. APFS_FILE *apfs_freopen(const char *pathname, const char *mode, APFS_FILE *stream);
  44. int apfs_remove(const char *pathname);
  45. #undef stdin
  46. #undef stdout
  47. #undef stderr
  48. #define stdin ((APFS_FILE*)1)
  49. #define stdout ((APFS_FILE*)2)
  50. #define stderr ((APFS_FILE*)3)
  51. #undef BUFSIZ
  52. #define BUFSIZ 256
  53. #define EOF (-1)
  54. #ifndef SEEK_SET
  55. #define SEEK_SET 0
  56. #define SEEK_CUR 1
  57. #define SEEK_END 2
  58. #endif
  59. #define FILE APFS_FILE
  60. #define fopen(p,m) apfs_fopen(p,m)
  61. #define fprintf(stream, format, args...) apfs_fprintf(stream, format, ##args)
  62. #define fflush(s) apfs_fflush(s)
  63. #define fread(ptr,size,nmemb, stream) apfs_fread(ptr, size, nmemb, stream)
  64. #define fwrite(ptr, size, nmemb, stream) apfs_fwrite(ptr, size, nmemb, stream)
  65. #define fputs(s, stream) apfs_fputs(s, stream)
  66. #define fgets(s, size, stream) apfs_fgets(s, size, stream)
  67. #define clearerr(stream) apfs_clearerr(stream)
  68. #define fseek(stream, offset, whence) apfs_fseek(stream, offset, whence)
  69. #define ferror(stream) apfs_ferror(stream)
  70. #define fclose(stream) apfs_fclose(stream)
  71. #define tmpfile() apfs_tmpfile()
  72. #undef getc
  73. #define getc(stream) apfs_getc(stream)
  74. #define ungetc(c, stream) apfs_ungetc(c, stream)
  75. #define feof(stream) apfs_ferror(stream)
  76. #define ftell(stream) apfs_ftell(stream)
  77. #define freopen(pathname, mode, stream) apfs_freopen(pathname, mode, stream)
  78. #define remove(pathname) apfs_remove(pathname)
  79. #if !defined(__APPLE__)
  80. int sprintf(char *str, const char *format, ...);
  81. #endif
  82. #ifdef __cplusplus
  83. }
  84. #endif