posix-mock.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Formatting library for C++ - mocks of POSIX functions
  2. //
  3. // Copyright (c) 2012 - present, Victor Zverovich
  4. // All rights reserved.
  5. //
  6. // For the license information refer to format.h.
  7. #ifndef FMT_POSIX_TEST_H
  8. #define FMT_POSIX_TEST_H
  9. #include <errno.h>
  10. #include <locale.h>
  11. #include <stdio.h>
  12. #ifdef __APPLE__
  13. # include <xlocale.h>
  14. #endif
  15. #ifdef _WIN32
  16. # include <windows.h>
  17. #else
  18. # include <sys/param.h> // for FreeBSD version
  19. # include <sys/types.h> // for ssize_t
  20. #endif
  21. #ifndef _MSC_VER
  22. struct stat;
  23. #endif
  24. namespace test {
  25. #ifndef _MSC_VER
  26. // Size type for read and write.
  27. typedef size_t size_t;
  28. typedef ssize_t ssize_t;
  29. int open(const char* path, int oflag, int mode);
  30. int fstat(int fd, struct stat* buf);
  31. #else
  32. typedef unsigned size_t;
  33. typedef int ssize_t;
  34. errno_t sopen_s(int* pfh, const char* filename, int oflag, int shflag,
  35. int pmode);
  36. #endif
  37. #ifndef _WIN32
  38. long sysconf(int name);
  39. #else
  40. DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
  41. #endif
  42. int close(int fildes);
  43. int dup(int fildes);
  44. int dup2(int fildes, int fildes2);
  45. FILE* fdopen(int fildes, const char* mode);
  46. ssize_t read(int fildes, void* buf, size_t nbyte);
  47. ssize_t write(int fildes, const void* buf, size_t nbyte);
  48. #ifndef _WIN32
  49. int pipe(int fildes[2]);
  50. #else
  51. int pipe(int* pfds, unsigned psize, int textmode);
  52. #endif
  53. FILE* fopen(const char* filename, const char* mode);
  54. int fclose(FILE* stream);
  55. int(fileno)(FILE* stream);
  56. #if defined(FMT_LOCALE) && !defined(_WIN32)
  57. locale_t newlocale(int category_mask, const char* locale, locale_t base);
  58. #endif
  59. } // namespace test
  60. #define FMT_SYSTEM(call) test::call
  61. #endif // FMT_POSIX_TEST_H