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