]> git.pond.sub.org Git - empserver/commitdiff
Change naming convention of POSIX emulation layer for Windows
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 13 Apr 2009 17:55:12 +0000 (19:55 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 30 Nov 2009 18:45:28 +0000 (19:45 +0100)
Use prefix w32 instead of posix: Rename posixfile.c, posixio.c to
w32file.c, w32io.c.  Rename posix_accept(), posix_bind(),
posix_close(), posix_fd2socket(), posix_listen(), posix_mkdir(),
posix_setsockopt(), posix_shutdown(), posix_socket() to w32_accept(),
w32_bind(), w32_fd2socket(), w32_list(), w32_mkdir(),
w32_setsockopt(), w32_shutdown(), w32_socket().

src/lib/empthread/ntthread.c
src/lib/w32/posixfile.c [deleted file]
src/lib/w32/posixio.c [deleted file]
src/lib/w32/sys/socket.h
src/lib/w32/unistd.h
src/lib/w32/w32file.c [new file with mode: 0644]
src/lib/w32/w32io.c [new file with mode: 0644]
src/lib/w32/w32sockets.c

index 53e20848d3892d6cd0c1972b4872c9d64b988fc1..579672204865d586a2c7a68b77b055565ae61e01 100644 (file)
@@ -546,7 +546,7 @@ empth_select(int fd, int flags, struct timeval *timeout)
     hEventObject[0] = WSACreateEvent();
     hEventObject[1] = pThread->hThreadEvent;
 
-    sock = posix_fd2socket(fd);
+    sock = w32_fd2socket(fd);
     CANT_HAPPEN(sock == (SOCKET)-1);
 
     events = 0;
diff --git a/src/lib/w32/posixfile.c b/src/lib/w32/posixfile.c
deleted file mode 100644 (file)
index f46f10c..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- *  ---
- *
- *  See files README, COPYING and CREDITS in the root of the source
- *  tree for related information and legal notices.  It is expected
- *  that future projects/authors will amend these files as needed.
- *
- *  ---
- *
- *  posixfile.c: POSIX equivalents for file operations
- *
- *  Known contributors to this file:
- *     Ron Koenderink, 2007
- */
-
-#include <config.h>
-
-#include <direct.h>
-#include <io.h>
-#include "unistd.h"
-
-/*
- * POSIX equivalent for mkdir().
- * Windows does not set the permission directly with mkdir().
- */
-int
-posix_mkdir(const char *dirname, mode_t perm)
-{
-    int result;
-
-    result = _mkdir(dirname);
-    if (result < 0)
-       return -1;
-    return _chmod(dirname, perm);
-}
diff --git a/src/lib/w32/posixio.c b/src/lib/w32/posixio.c
deleted file mode 100644 (file)
index 257e726..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- *  ---
- *
- *  See files README, COPYING and CREDITS in the root of the source
- *  tree for related information and legal notices.  It is expected
- *  that future projects/authors will amend these files as needed.
- *
- *  ---
- *
- *  posixio.c: POSIX I/O emulation layer for Windows
- *
- *  Known contributors to this file:
- *     Ron Koenderink, 2007
- *     Markus Armbruster, 2007-2009
- */
-
-/*
- * POSIX sockets are file descriptors.  Windows sockets are something
- * else, with a separate set of functions to operate on them.  To
- * present a more POSIX-like interface to our application code, we
- * provide a compatibility layer that wraps file descriptors around
- * sockets.
- */
-
-#include <config.h>
-
-#include <errno.h>
-#include <io.h>
-#include <stdlib.h>
-#include <string.h>
-#include "misc.h"
-#include "sys/uio.h"
-
-int (*w32_close_function)(int) = _close;
-int (*w32_read_function)(int, void *, unsigned) = _read;
-int (*w32_write_function)(int, const void *, unsigned) = _write;
-
-/*
- * POSIX equivalent for readv
- * Modelled after the GNU's libc/sysdeps/posix/readv.c
- */
-ssize_t
-readv(int fd, const struct iovec *iov, int iovcnt)
-{
-    int i;
-    unsigned char *buffer, *buffer_location;
-    size_t total_bytes = 0;
-    int bytes_read;
-    size_t bytes_left;
-
-    for (i = 0; i < iovcnt; i++) {
-       total_bytes += iov[i].iov_len;
-    }
-
-    buffer = malloc(total_bytes);
-    if (buffer == NULL && total_bytes != 0) {
-       errno = ENOMEM;
-       return -1;
-    }
-
-    bytes_read = read(fd, buffer, total_bytes);
-    if (bytes_read <= 0) {
-       free(buffer);
-       return -1;
-    }
-
-    bytes_left = bytes_read;
-    buffer_location = buffer;
-    for (i = 0; i < iovcnt; i++) {
-       size_t copy = MIN(iov[i].iov_len, bytes_left);
-
-       memcpy(iov[i].iov_base, buffer_location, copy);
-
-       buffer_location += copy;
-       bytes_left -= copy;
-       if (bytes_left == 0)
-           break;
-    }
-
-    free(buffer);
-
-    return bytes_read;
-}
-
-/*
- * POSIX equivalent for writev
- * Modelled after the GNU's libc/sysdeps/posix/writev.c
- */
-ssize_t
-writev(int fd, const struct iovec *iov, int iovcnt)
-{
-    int i;
-    unsigned char *buffer, *buffer_location;
-    size_t total_bytes = 0;
-    int bytes_written;
-
-    for (i = 0; i < iovcnt; i++)
-       total_bytes += iov[i].iov_len;
-
-    buffer = malloc(total_bytes);
-    if (buffer == NULL && total_bytes != 0) {
-       errno = ENOMEM;
-       return -1;
-    }
-
-    buffer_location = buffer;
-    for (i = 0; i < iovcnt; i++) {
-       memcpy(buffer_location, iov[i].iov_base, iov[i].iov_len);
-       buffer_location += iov[i].iov_len;
-    }
-
-    bytes_written = write(fd, buffer, total_bytes);
-
-    free(buffer);
-
-    if (bytes_written <= 0)
-       return -1;
-    return bytes_written;
-}
index f9ed35fac6f7c8bae308365d25b3c2bb889651ae..ac5927acd4461f99555dbb89c619a6004c9444f5 100644 (file)
 typedef int socklen_t;
 
 #define accept(fd, addr, addrlen) \
-    posix_accept((fd), (addr), (addrlen))
+    w32_accept((fd), (addr), (addrlen))
 #define bind(fd, name, namelen) \
-    posix_bind((fd), (name), (namelen))
+    w32_bind((fd), (name), (namelen))
 #define listen(fd, backlog) \
-    posix_listen((fd), (backlog))
+    w32_listen((fd), (backlog))
 #define setsockopt(fd, level, optname, optval, optlen) \
-    posix_setsockopt((fd), (level), (optname), (optval), (optlen))
+    w32_setsockopt((fd), (level), (optname), (optval), (optlen))
 #define shutdown(fd, how) \
-    posix_shutdown((fd), (how))
+    w32_shutdown((fd), (how))
 #define socket(domain, type, protocol) \
-    posix_socket((domain), (type), (protocol))
+    w32_socket((domain), (type), (protocol))
 
-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 int w32_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
+extern int w32_bind(int fd, const struct sockaddr *name, socklen_t namelen);
+extern int w32_listen(int fd, int backlog);
+extern int w32_setsockopt(int fd, int level, int optname,
+                         const void *optval, socklen_t optlen);
+extern int w32_shutdown(int fd, int how);
+extern int w32_socket(int domain, int type, int protocol);
 
 /* Low-level stuff specific to the emulation */
-extern SOCKET posix_fd2socket(int fd);
+extern SOCKET w32_fd2socket(int fd);
 extern void w32_set_winsock_errno(void);
 extern int w32_socket_init(void);
 
index 22944494608e9ecf74dd587019ee5591fc898ed1..1696e29e40724ac0eb16ea13627c68fe67d46a0e 100644 (file)
@@ -60,11 +60,11 @@ extern char *optarg;
 extern int optind, opterr, optopt;
 
 /*
- * posixfile.c
+ * w32file.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);
+#define mkdir(dir, perm)    w32_mkdir((dir), (perm))
+extern int w32_mkdir(const char *dirname, mode_t perm);
 
 /* Should be in sys/stat.h */
 #ifndef S_IRUSR
diff --git a/src/lib/w32/w32file.c b/src/lib/w32/w32file.c
new file mode 100644 (file)
index 0000000..f249e73
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                           Ken Stevens, Steve McClure
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  ---
+ *
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
+ *
+ *  ---
+ *
+ *  w32file.c: POSIX file operations emulation layer for Windows
+ *
+ *  Known contributors to this file:
+ *     Ron Koenderink, 2007
+ */
+
+#include <config.h>
+
+#include <direct.h>
+#include <io.h>
+#include "unistd.h"
+
+/*
+ * POSIX-compatible replacement for mkdir().
+ * Windows' mkdir() lacks the second parameter.
+ */
+int
+w32_mkdir(const char *dirname, mode_t perm)
+{
+    int result;
+
+    result = _mkdir(dirname);
+    if (result < 0)
+       return -1;
+    return _chmod(dirname, perm);
+}
diff --git a/src/lib/w32/w32io.c b/src/lib/w32/w32io.c
new file mode 100644 (file)
index 0000000..8274c85
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                           Ken Stevens, Steve McClure
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  ---
+ *
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
+ *
+ *  ---
+ *
+ *  w32io.c: POSIX I/O emulation layer for Windows
+ *
+ *  Known contributors to this file:
+ *     Ron Koenderink, 2007
+ *     Markus Armbruster, 2007-2009
+ */
+
+/*
+ * POSIX sockets are file descriptors.  Windows sockets are something
+ * else, with a separate set of functions to operate on them.  To
+ * present a more POSIX-like interface to our application code, we
+ * provide a compatibility layer that wraps file descriptors around
+ * sockets.
+ */
+
+#include <config.h>
+
+#include <errno.h>
+#include <io.h>
+#include <stdlib.h>
+#include <string.h>
+#include "misc.h"
+#include "sys/uio.h"
+
+int (*w32_close_function)(int) = _close;
+int (*w32_read_function)(int, void *, unsigned) = _read;
+int (*w32_write_function)(int, const void *, unsigned) = _write;
+
+/*
+ * POSIX equivalent for readv
+ * Modelled after the GNU's libc/sysdeps/posix/readv.c
+ */
+ssize_t
+readv(int fd, const struct iovec *iov, int iovcnt)
+{
+    int i;
+    unsigned char *buffer, *buffer_location;
+    size_t total_bytes = 0;
+    int bytes_read;
+    size_t bytes_left;
+
+    for (i = 0; i < iovcnt; i++) {
+       total_bytes += iov[i].iov_len;
+    }
+
+    buffer = malloc(total_bytes);
+    if (buffer == NULL && total_bytes != 0) {
+       errno = ENOMEM;
+       return -1;
+    }
+
+    bytes_read = read(fd, buffer, total_bytes);
+    if (bytes_read <= 0) {
+       free(buffer);
+       return -1;
+    }
+
+    bytes_left = bytes_read;
+    buffer_location = buffer;
+    for (i = 0; i < iovcnt; i++) {
+       size_t copy = MIN(iov[i].iov_len, bytes_left);
+
+       memcpy(iov[i].iov_base, buffer_location, copy);
+
+       buffer_location += copy;
+       bytes_left -= copy;
+       if (bytes_left == 0)
+           break;
+    }
+
+    free(buffer);
+
+    return bytes_read;
+}
+
+/*
+ * POSIX equivalent for writev
+ * Modelled after the GNU's libc/sysdeps/posix/writev.c
+ */
+ssize_t
+writev(int fd, const struct iovec *iov, int iovcnt)
+{
+    int i;
+    unsigned char *buffer, *buffer_location;
+    size_t total_bytes = 0;
+    int bytes_written;
+
+    for (i = 0; i < iovcnt; i++)
+       total_bytes += iov[i].iov_len;
+
+    buffer = malloc(total_bytes);
+    if (buffer == NULL && total_bytes != 0) {
+       errno = ENOMEM;
+       return -1;
+    }
+
+    buffer_location = buffer;
+    for (i = 0; i < iovcnt; i++) {
+       memcpy(buffer_location, iov[i].iov_base, iov[i].iov_len);
+       buffer_location += iov[i].iov_len;
+    }
+
+    bytes_written = write(fd, buffer, total_bytes);
+
+    free(buffer);
+
+    if (bytes_written <= 0)
+       return -1;
+    return bytes_written;
+}
index 13feba3e31de4b53963c6ff32e2a46689b4ee202..318949d4bae01d737cd23c56267acea58488f8b7 100644 (file)
@@ -59,7 +59,7 @@
 #define W32_SOCKET_TO_FD(fh) (_open_osfhandle((long)(fh), O_RDWR | O_BINARY))
 
 SOCKET
-posix_fd2socket(int fd)
+w32_fd2socket(int fd)
 {
     return W32_FD_TO_SOCKET(fd);
 }
@@ -124,7 +124,7 @@ w32_set_winsock_errno(void)
  */
 #undef accept
 int
-posix_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
+w32_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
 {
     SOCKET sock;
 
@@ -142,7 +142,7 @@ posix_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
  */
 #undef bind
 int
-posix_bind(int fd, const struct sockaddr *name, socklen_t namelen)
+w32_bind(int fd, const struct sockaddr *name, socklen_t namelen)
 {
     SOCKET_FUNCTION(bind(sock, name, namelen));
 }
@@ -152,7 +152,7 @@ posix_bind(int fd, const struct sockaddr *name, socklen_t namelen)
  */
 #undef listen
 int
-posix_listen(int fd, int backlog)
+w32_listen(int fd, int backlog)
 {
     SOCKET_FUNCTION(listen(sock, backlog));
 }
@@ -162,8 +162,8 @@ posix_listen(int fd, int backlog)
  */
 #undef setsockopt
 int
-posix_setsockopt(int fd, int level, int optname,
-                     const void *optval, socklen_t optlen)
+w32_setsockopt(int fd, int level, int optname,
+              const void *optval, socklen_t optlen)
 {
     /*
      * SO_REUSEADDR requests to permit another bind even when the
@@ -186,7 +186,7 @@ posix_setsockopt(int fd, int level, int optname,
  */
 #undef shutdown
 int
-posix_shutdown(int fd, int how)
+w32_shutdown(int fd, int how)
 {
     SOCKET_FUNCTION(shutdown(sock, how));
 }
@@ -196,7 +196,7 @@ posix_shutdown(int fd, int how)
  */
 #undef socket
 int
-posix_socket(int domain, int type, int protocol)
+w32_socket(int domain, int type, int protocol)
 {
     SOCKET sock;