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