blob: e01a73dabbccf26b6a086a77d9942f8a155470d5 [file] [log] [blame]
Jan Kundrátce0606e2021-12-09 17:42:43 +01001#ifndef _UNISTD_H
2#define _UNISTD_H 1
3
4/* This is intended as a drop-in replacement for unistd.h on Windows.
5 * Please add functionality as neeeded.
6 * https://stackoverflow.com/a/826027/1202830
7 */
8
9#include <stdlib.h>
10#include <io.h>
11#include <process.h> /* for getpid() and the exec..() family */
12#include <direct.h> /* for _getcwd() and _chdir() */
13
14#define srandom srand
15#define random rand
16
17/* Values for the second argument to access.
18 These may be OR'd together. */
19#define R_OK 4 /* Test for read permission. */
20#define W_OK 2 /* Test for write permission. */
21//#define X_OK 1 /* execute permission - unsupported in windows*/
22#define F_OK 0 /* Test for existence. */
23
24#define access _access
25#define dup2 _dup2
26#define execve _execve
27#define ftruncate _chsize
28#define unlink _unlink
29#define fileno _fileno
30#define getcwd _getcwd
31#define chdir _chdir
32#define isatty _isatty
33#define lseek _lseek
34/* 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(). */
35
36#ifdef _WIN64
37#define ssize_t __int64
38#else
39#define ssize_t long
40#endif
41
42#define STDIN_FILENO 0
43#define STDOUT_FILENO 1
44#define STDERR_FILENO 2
45/* should be in some equivalent to <sys/types.h> */
46typedef __int8 int8_t;
47typedef __int16 int16_t;
48typedef __int32 int32_t;
49typedef __int64 int64_t;
50typedef unsigned __int8 uint8_t;
51typedef unsigned __int16 uint16_t;
52typedef unsigned __int32 uint32_t;
53typedef unsigned __int64 uint64_t;
54
55#endif /* unistd.h */