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