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  */
7 
8 #include <stdlib.h>
9 #include <io.h>
10 #include <process.h> /* for getpid() and the exec..() family */
11 #include <direct.h> /* for _getcwd() and _chdir() */
12 
13 #define srandom srand
14 #define random rand
15 
16 /* Values for the second argument to access.
17    These may be OR'd together.  */
18 #define R_OK    4       /* Test for read permission.  */
19 #define W_OK    2       /* Test for write permission.  */
20 //#define   X_OK    1   /* execute permission - unsupported in windows*/
21 #define F_OK    0       /* Test for existence.  */
22 
23 #define access _access
24 #define dup2 _dup2
25 #define execve _execve
26 #define ftruncate _chsize
27 #define unlink _unlink
28 #define fileno _fileno
29 #define getcwd _getcwd
30 #define chdir _chdir
31 #define isatty _isatty
32 #define lseek _lseek
33 /* 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(). */
34 
35 #define ssize_t int
36 
37 #define STDIN_FILENO 0
38 #define STDOUT_FILENO 1
39 #define STDERR_FILENO 2
40 /* should be in some equivalent to <sys/types.h> */
41 typedef __int8            int8_t;
42 typedef __int16           int16_t;
43 typedef __int32           int32_t;
44 typedef __int64           int64_t;
45 typedef unsigned __int8   uint8_t;
46 typedef unsigned __int16  uint16_t;
47 typedef unsigned __int32  uint32_t;
48 typedef unsigned __int64  uint64_t;
49 
50 #endif /* unistd.h  */
51