1 /* 2 Mocks of POSIX functions 3 4 Copyright (c) 2012-2015, Victor Zverovich 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions are met: 9 10 1. Redistributions of source code must retain the above copyright notice, this 11 list of conditions and the following disclaimer. 12 2. Redistributions in binary form must reproduce the above copyright notice, 13 this list of conditions and the following disclaimer in the documentation 14 and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef FMT_POSIX_TEST_H 29 #define FMT_POSIX_TEST_H 30 31 #include <errno.h> 32 #include <stdio.h> 33 34 #ifdef _WIN32 35 # include <windows.h> 36 #else 37 # include <sys/types.h> // for ssize_t 38 #endif 39 40 #ifndef _MSC_VER 41 struct stat; 42 #endif 43 44 namespace test { 45 46 #ifndef _MSC_VER 47 // Size type for read and write. 48 typedef size_t size_t; 49 typedef ssize_t ssize_t; 50 int open(const char *path, int oflag, int mode); 51 int fstat(int fd, struct stat *buf); 52 #else 53 typedef unsigned size_t; 54 typedef int ssize_t; 55 errno_t sopen_s( 56 int* pfh, const char *filename, int oflag, int shflag, int pmode); 57 #endif 58 59 #ifndef _WIN32 60 long sysconf(int name); 61 #else 62 DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); 63 #endif 64 65 int close(int fildes); 66 67 int dup(int fildes); 68 int dup2(int fildes, int fildes2); 69 70 FILE *fdopen(int fildes, const char *mode); 71 72 ssize_t read(int fildes, void *buf, size_t nbyte); 73 ssize_t write(int fildes, const void *buf, size_t nbyte); 74 75 #ifndef _WIN32 76 int pipe(int fildes[2]); 77 #else 78 int pipe(int *pfds, unsigned psize, int textmode); 79 #endif 80 81 FILE *fopen(const char *filename, const char *mode); 82 int fclose(FILE *stream); 83 int (fileno)(FILE *stream); 84 } // namespace test 85 86 #define FMT_SYSTEM(call) test::call 87 88 #endif // FMT_POSIX_TEST_H 89