]> git.pond.sub.org Git - empserver/blob - src/lib/w32/unistd.h
(getopt) [_WIN32]: In order to prevent namespace conflict between MSC and
[empserver] / src / lib / w32 / unistd.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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 #ifndef UNISTD_H
35 #define UNISTD_H
36
37 #include <io.h>
38 #include <stdio.h>
39 #undef fileno
40 #include "sys/socket.h"
41 #include <sys/stat.h>
42
43 /*
44  * getopt.c
45  */
46 extern int getopt(int, char * const[], const char *);
47 extern char *optarg;
48 extern int optind, opterr, optopt;
49
50 /*
51  * posixfile.c
52  */
53 #define mkdir(dir, perm)    posix_mkdir((dir), (perm))
54
55 extern int posix_mkdir(const char *dirname, int perm);
56
57 /*
58  * posixio.c
59  */
60 #ifndef S_IRUSR
61 #define S_IRUSR     _S_IREAD
62 #define S_IWUSR     _S_IWRITE
63 #define S_IXUSR     _S_IEXEC
64 #define S_IRWXU     S_IRUSR | S_IWUSR | S_IXUSR
65 #endif
66 #ifndef S_IRGRP
67 #define S_IRGRP     0
68 #define S_IWGRP     0
69 #define S_IXGRP     0
70 #define S_IRWXG     S_IRGRP | S_IWGRP | S_IXGRP
71 #endif
72 #ifndef S_IROTH
73 #define S_IROTH     0
74 #define S_IWOTH     0
75 #define S_IXOTH     0
76 #define S_IRWXO     S_IROTH | S_IWOTH | S_IXOTH
77 #endif
78
79 typedef int socklen_t;
80
81 #define accept(fd, addr, addrlen) \
82     posix_accept((fd), (addr), (addrlen))
83 #define bind(fd, name, namelen) \
84     posix_bind((fd), (name), (namelen))
85 #define listen(fd, backlog) \
86     posix_listen((fd), (backlog))
87 #define setsockopt(fd, level, optname, optval, optlen) \
88     posix_setsockopt((fd), (level), (optname), (optval), (optlen))
89 #define shutdown(fd, how) \
90     posix_shutdown((fd), (how))
91 #define socket(domain, type, protocol) \
92     posix_socket((domain), (type), (protocol))
93
94 #define close(fd) \
95     posix_close((fd))
96 #define creat(fname, pmode) \
97     posix_open((fname), _O_WRONLY | _O_CREAT |_O_TRUNC, (pmode))
98 #define fstat(fd, buffer) \
99     posix_fstat((fd), (buffer))
100 #define lseek(fd, offset, origin) \
101     posix_lseek((fd), (offset), (origin))
102 #define open(fname, oflag, ...) \
103     posix_open((fname), (oflag), __VA_ARGS__)
104 #define read    posix_read
105 #define write(fd, buffer, count) \
106     posix_write((fd), (buffer), (count))
107 #define fileno(stream) \
108     posix_fileno((stream))
109 #define fsync(fd) \
110     posix_fsync((fd))
111
112 #define O_NONBLOCK  1
113 #define F_RDLCK     0
114 #define F_WRLCK     1
115 #define F_GETFL     1
116 #define F_SETFL     2
117 #define F_SETLK     3
118 #define EWOULDBLOCK WSAEWOULDBLOCK
119 #define ENOTSOCK    WSAENOTSOCK
120
121 struct flock
122 {
123     int l_type;
124     int l_whence;
125     int l_start;
126     int l_len;
127 };
128
129 extern int posix_fd2socket(int fd);
130
131 extern int posix_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
132 extern int posix_bind(int fd, const struct sockaddr *name, int namelen);
133 extern int posix_listen(int fd, int backlog);
134 extern int posix_setsockopt(int fd, int level, int optname,
135                       const void *optval, int optlen);
136 extern int posix_shutdown(int fd, int how);
137 extern int posix_socket(int domain, int type, int protocol);
138
139 extern int posix_close(int fd);
140 extern int posix_fstat(int fd, struct stat *buffer);
141 extern int posix_lseek(int fd, long offset, int origin);
142 extern int posix_open(const char *fname, int oflag, ...);
143 extern int posix_read(int fd, void *buffer, unsigned int count);
144 extern int posix_write(int fd, const void *buffer, unsigned int count);
145
146 extern int posix_fileno(FILE *stream);
147 extern int posix_fsync(int fd);
148 extern int fcntl(int fd, int cmd, ...);
149 #endif /* UNISTD_H */