1 #ifndef _UNISTD_H
2 #define _UNISTD_H    1
3 
4 /* This file intended to serve as a drop-in replacement for
5  *  unistd.h on Windows
6  *  Please add functionality as neeeded
7  */
8 
9 #include <stdlib.h>
10 #include <io.h>
11 //#include <getopt.h> /* getopt at: https://gist.github.com/ashelly/7776712*/
12 #include <process.h> /* for getpid() and the exec..() family */
13 #include <direct.h> /* for _getcwd() and _chdir() */
14 
15 #define srandom srand
16 #define random rand
17 
18 /* Values for the second argument to access.
19    These may be OR'd together.  */
20 #define R_OK    4       /* Test for read permission.  */
21 #define W_OK    2       /* Test for write permission.  */
22 //#define   X_OK    1       /* execute permission - unsupported in windows*/
23 #define F_OK    0       /* Test for existence.  */
24 
25 #define access _access
26 #define dup2 _dup2
27 #define execve _execve
28 #define ftruncate _chsize
29 #define unlink _unlink
30 #define fileno _fileno
31 #define getcwd _getcwd
32 #define chdir _chdir
33 #define isatty _isatty
34 #define lseek _lseek
35 /* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */
36 
37 #define ssize_t int
38 
39 #define STDIN_FILENO 0
40 #define STDOUT_FILENO 1
41 #define STDERR_FILENO 2
42 /* should be in some equivalent to <sys/types.h> */
43 typedef __int8            int8_t;
44 typedef __int16           int16_t;
45 typedef __int32           int32_t;
46 typedef __int64           int64_t;
47 typedef unsigned __int8   uint8_t;
48 typedef unsigned __int16  uint16_t;
49 typedef unsigned __int32  uint32_t;
50 typedef unsigned __int64  uint64_t;
51 
52 #endif /* unistd.h  */
53