]> git.pond.sub.org Git - empserver/blob - src/lib/w32/unistd.h
Change naming convention of POSIX emulation layer for Windows
[empserver] / src / lib / w32 / unistd.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  unistd.h: POSIX emulation for Windows
29  *
30  *  Known contributors to this file:
31  *     Ron Koenderink, 2007
32  *     Markus Armbruster, 2007-2009
33  */
34
35 /*
36  * We can provide POSIX headers that don't exist in Windows, but we
37  * can't augment existing headers.  Some stuff that should be in such
38  * headers ends up here, and some in w32misc.h.  Can't be helped.
39  */
40
41 #ifndef UNISTD_H
42 #define UNISTD_H
43
44 /*
45  * We override system functions by defining them as macros.  This
46  * breaks if the system's declaration is included later.  Include them
47  * here.  Major name space pollution, can't be helped.
48  */
49 #include <io.h>
50 #include <direct.h>
51 #include <sys/stat.h>
52
53 #include "w32misc.h"
54
55 /*
56  * getopt.c
57  */
58 extern int getopt(int, char * const[], const char *);
59 extern char *optarg;
60 extern int optind, opterr, optopt;
61
62 /*
63  * w32file.c
64  */
65 /* Should be in sys/stat.h */
66 #define mkdir(dir, perm)    w32_mkdir((dir), (perm))
67 extern int w32_mkdir(const char *dirname, mode_t perm);
68
69 /* Should be in sys/stat.h */
70 #ifndef S_IRUSR
71 #define S_IRUSR     _S_IREAD
72 #define S_IWUSR     _S_IWRITE
73 #define S_IXUSR     _S_IEXEC
74 #define S_IRWXU     S_IRUSR | S_IWUSR | S_IXUSR
75 #endif
76 #ifndef S_IRGRP
77 #define S_IRGRP     0
78 #define S_IWGRP     0
79 #define S_IXGRP     0
80 #define S_IRWXG     S_IRGRP | S_IWGRP | S_IXGRP
81 #endif
82 #ifndef S_IROTH
83 #define S_IROTH     0
84 #define S_IWOTH     0
85 #define S_IXOTH     0
86 #define S_IRWXO     S_IROTH | S_IWOTH | S_IXOTH
87 #endif
88
89 /* Should be in fcntl.h */
90 #define O_NONBLOCK  1
91
92 #define F_GETFL     1
93 #define F_SETFL     2
94
95 extern int fcntl(int fd, int cmd, ...);
96
97 /* Stuff that actually belongs here */
98 #define close(fd) w32_close_function((fd))
99 extern int (*w32_close_function)(int);
100 #define ftruncate(fd, length) _chsize((fd), (length))
101 #define read(fd, buf, sz) w32_read_function((fd), (buf), (sz))
102 extern int (*w32_read_function)(int, void *, unsigned);
103 #define write(fd, buf, sz) w32_write_function((fd), (buf), (sz))
104 extern int (*w32_write_function)(int, const void *, unsigned);
105
106 #endif /* UNISTD_H */