]> git.pond.sub.org Git - empserver/blob - src/lib/w32/unistd.h
Update copyright notice
[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 WIN32
29  *
30  *  Known contributors to this file:
31  *     Ron Koenderink, 2007
32  */
33
34 /*
35  * We can provide POSIX headers that don't exist in Windows, but we
36  * can't augment existing headers.  Some stuff that should be in such
37  * headers ends up here, and some in w32misc.h.  Can't be helped.
38  */
39
40 #ifndef UNISTD_H
41 #define UNISTD_H
42
43 /*
44  * We override system functions by defining them as macros.  This
45  * breaks if the system's declaration is included later.  Include them
46  * here.  Major name space pollution, can't be helped.
47  */
48 #include <io.h>
49 #include <stdio.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  * posixfile.c
64  */
65 /* Should be in sys/stat.h */
66 #define mkdir(dir, perm)    posix_mkdir((dir), (perm))
67 extern int posix_mkdir(const char *dirname, mode_t perm);
68
69 /*
70  * posixio.c
71  */
72 /* Should be in sys/stat.h */
73 #ifndef S_IRUSR
74 #define S_IRUSR     _S_IREAD
75 #define S_IWUSR     _S_IWRITE
76 #define S_IXUSR     _S_IEXEC
77 #define S_IRWXU     S_IRUSR | S_IWUSR | S_IXUSR
78 #endif
79 #ifndef S_IRGRP
80 #define S_IRGRP     0
81 #define S_IWGRP     0
82 #define S_IXGRP     0
83 #define S_IRWXG     S_IRGRP | S_IWGRP | S_IXGRP
84 #endif
85 #ifndef S_IROTH
86 #define S_IROTH     0
87 #define S_IWOTH     0
88 #define S_IXOTH     0
89 #define S_IRWXO     S_IROTH | S_IWOTH | S_IXOTH
90 #endif
91 #define fstat(fd, buffer) \
92     posix_fstat((fd), (buffer))
93 extern int posix_fstat(int fd, struct stat *buffer);
94
95 /* Should be in fcntl.h */
96 #define O_NONBLOCK  1
97
98 #define F_RDLCK     0
99 #define F_WRLCK     1
100 #define F_GETFL     1
101 #define F_SETFL     2
102 #define F_SETLK     3
103
104 struct flock
105 {
106     short l_type;
107     short l_whence;
108     off_t l_start;
109     off_t l_len;
110     /* intentionally missing: pid_t l_pid */
111 };
112
113 #define creat(fname, pmode) \
114     posix_open((fname), _O_WRONLY | _O_CREAT |_O_TRUNC, (pmode))
115 #define open(fname, oflag, ...) \
116     posix_open((fname), (oflag), __VA_ARGS__)
117 extern int posix_open(const char *fname, int oflag, ...);
118 extern int fcntl(int fd, int cmd, ...);
119
120 /* Stuff that actually belongs here */
121 #define close(fd) \
122     posix_close((fd))
123 #define lseek(fd, offset, origin) \
124     posix_lseek((fd), (offset), (origin))
125 #define read    posix_read
126 #define write(fd, buffer, count) \
127     posix_write((fd), (buffer), (count))
128 #define fsync(fd) \
129     posix_fsync((fd))
130 extern int ftruncate(int fd, off_t length);
131 extern int posix_close(int fd);
132 extern off_t posix_lseek(int fd, off_t offset, int origin);
133 extern ssize_t posix_read(int fd, void *buffer, size_t count);
134 extern ssize_t posix_write(int fd, const void *buffer, size_t count);
135 extern int posix_fsync(int fd);
136
137 /* Low-level stuff specific to the emulation */
138 extern int posix_fd2socket(int fd);
139
140 #endif /* UNISTD_H */