]> git.pond.sub.org Git - empserver/blobdiff - src/lib/w32/unistd.h
(posix_accept, posix_bind, posix_listen, posix_setsockopt,
[empserver] / src / lib / w32 / unistd.h
index 65fca5c6079efe6f8f55ca27451abb7d9f2c9029..2e4cb1ed19a2082ba2ec151904158607ac916ce7 100644 (file)
  *     Ron Koenderink, 2007
  */
 
+/*
+ * We can provide POSIX headers that don't exist in Windows, but we
+ * can't augment existing headers.  Some stuff that should be in such
+ * headers ends up here, and some in w32misc.h.  Can't be helped.
+ */
+
 #ifndef UNISTD_H
 #define UNISTD_H
 
+/*
+ * We override system functions by defining them as macros.  This
+ * breaks if the system's declaration is included later.  Include them
+ * here.  Major name space pollution, can't be helped.
+ */
 #include <io.h>
 #include <stdio.h>
 #include <direct.h>
-#include "sys/socket.h"
 #include <sys/stat.h>
-#include <ws2tcpip.h>
 
 #include "w32misc.h"
 
@@ -53,13 +62,14 @@ extern int optind, opterr, optopt;
 /*
  * posixfile.c
  */
+/* Should be in sys/stat.h */
 #define mkdir(dir, perm)    posix_mkdir((dir), (perm))
-
 extern int posix_mkdir(const char *dirname, mode_t perm);
 
 /*
  * posixio.c
  */
+/* Should be in sys/stat.h */
 #ifndef S_IRUSR
 #define S_IRUSR            _S_IREAD
 #define S_IWUSR            _S_IWRITE
@@ -78,47 +88,18 @@ extern int posix_mkdir(const char *dirname, mode_t perm);
 #define S_IXOTH            0
 #define S_IRWXO            S_IROTH | S_IWOTH | S_IXOTH
 #endif
-
-typedef int socklen_t;
-
-#define accept(fd, addr, addrlen) \
-    posix_accept((fd), (addr), (addrlen))
-#define bind(fd, name, namelen) \
-    posix_bind((fd), (name), (namelen))
-#define listen(fd, backlog) \
-    posix_listen((fd), (backlog))
-#define setsockopt(fd, level, optname, optval, optlen) \
-    posix_setsockopt((fd), (level), (optname), (optval), (optlen))
-#define shutdown(fd, how) \
-    posix_shutdown((fd), (how))
-#define socket(domain, type, protocol) \
-    posix_socket((domain), (type), (protocol))
-
-#define close(fd) \
-    posix_close((fd))
-#define creat(fname, pmode) \
-    posix_open((fname), _O_WRONLY | _O_CREAT |_O_TRUNC, (pmode))
 #define fstat(fd, buffer) \
     posix_fstat((fd), (buffer))
-#define lseek(fd, offset, origin) \
-    posix_lseek((fd), (offset), (origin))
-#define open(fname, oflag, ...) \
-    posix_open((fname), (oflag), __VA_ARGS__)
-#define read   posix_read
-#define write(fd, buffer, count) \
-    posix_write((fd), (buffer), (count))
-#define fsync(fd) \
-    posix_fsync((fd))
+extern int posix_fstat(int fd, struct stat *buffer);
 
+/* Should be in fcntl.h */
 #define O_NONBLOCK  1
+
 #define F_RDLCK            0
 #define F_WRLCK            1
 #define F_GETFL            1
 #define F_SETFL            2
 #define F_SETLK            3
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTSOCK    WSAENOTSOCK
-#define EAFNOSUPPORT   WSAEAFNOSUPPORT
 
 struct flock
 {
@@ -128,27 +109,31 @@ struct flock
     off_t l_len;
     /* intentionally missing: pid_t l_pid */
 };
+#define creat(fname, pmode) \
+    posix_open((fname), _O_WRONLY | _O_CREAT |_O_TRUNC, (pmode))
+#define open(fname, oflag, ...) \
+    posix_open((fname), (oflag), __VA_ARGS__)
+extern int posix_open(const char *fname, int oflag, ...);
 
-extern int posix_fd2socket(int fd);
-
-extern int posix_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
-extern int posix_bind(int fd, const struct sockaddr *name, socklen_t namelen);
-extern int posix_listen(int fd, int backlog);
-extern int posix_setsockopt(int fd, int level, int optname,
-                     const void *optval, socklen_t optlen);
-extern int posix_shutdown(int fd, int how);
-extern int posix_socket(int domain, int type, int protocol);
-extern const char *inet_ntop(int af, const void *src, char *dst,
-                            socklen_t cnt);
-
+/* Stuff that belongs here */
+#define close(fd) \
+    posix_close((fd))
+#define lseek(fd, offset, origin) \
+    posix_lseek((fd), (offset), (origin))
+#define read   posix_read
+#define write(fd, buffer, count) \
+    posix_write((fd), (buffer), (count))
+#define fsync(fd) \
+    posix_fsync((fd))
 extern int posix_close(int fd);
-extern int posix_fstat(int fd, struct stat *buffer);
 extern off_t posix_lseek(int fd, off_t offset, int origin);
-extern int posix_open(const char *fname, int oflag, ...);
 extern ssize_t posix_read(int fd, void *buffer, size_t count);
 extern ssize_t posix_write(int fd, const void *buffer, size_t count);
-
-extern int posix_fileno(FILE *stream);
 extern int posix_fsync(int fd);
 extern int fcntl(int fd, int cmd, ...);
+
+/* Low-level stuff specific to the emulation */
+extern int posix_fd2socket(int fd);
+
 #endif /* UNISTD_H */
+extern int posix_fileno(FILE *stream);