posix-mock.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # include <locale> // for libc++ locale_win32.h
  18. #else
  19. # include <sys/param.h> // for FreeBSD version
  20. # include <sys/types.h> // for ssize_t
  21. #endif
  22. #ifndef _MSC_VER
  23. struct stat;
  24. #endif
  25. namespace test {
  26. #ifndef _MSC_VER
  27. // Size type for read and write.
  28. typedef size_t size_t;
  29. typedef ssize_t ssize_t;
  30. int open(const char* path, int oflag, int mode);
  31. int fstat(int fd, struct stat* buf);
  32. #else
  33. typedef unsigned size_t;
  34. typedef int ssize_t;
  35. errno_t sopen_s(int* pfh, const char* filename, int oflag, int shflag,
  36. int pmode);
  37. #endif
  38. #ifndef _WIN32
  39. long sysconf(int name);
  40. #else
  41. DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
  42. #endif
  43. int close(int fildes);
  44. int dup(int fildes);
  45. int dup2(int fildes, int fildes2);
  46. FILE* fdopen(int fildes, const char* mode);
  47. ssize_t read(int fildes, void* buf, size_t nbyte);
  48. ssize_t write(int fildes, const void* buf, size_t nbyte);
  49. #ifndef _WIN32
  50. int pipe(int fildes[2]);
  51. #else
  52. int pipe(int* pfds, unsigned psize, int textmode);
  53. #endif
  54. FILE* fopen(const char* filename, const char* mode);
  55. int fclose(FILE* stream);
  56. int(fileno)(FILE* stream);
  57. #if defined(FMT_LOCALE) && (!defined(_WIN32) || defined(_LIBCPP_VERSION))
  58. locale_t newlocale(int category_mask, const char* locale, locale_t base);
  59. #endif
  60. } // namespace test
  61. #define FMT_SYSTEM(call) test::call
  62. #endif // FMT_POSIX_TEST_H