hEventObject[0] = WSACreateEvent();
hEventObject[1] = pThread->hThreadEvent;
- sock = posix_fd2socket(fd);
+ sock = w32_fd2socket(fd);
CANT_HAPPEN(sock == (SOCKET)-1);
events = 0;
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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;
-}
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);
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
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+}
#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);
}
*/
#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;
*/
#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));
}
*/
#undef listen
int
-posix_listen(int fd, int backlog)
+w32_listen(int fd, int backlog)
{
SOCKET_FUNCTION(listen(sock, 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
*/
#undef shutdown
int
-posix_shutdown(int fd, int how)
+w32_shutdown(int fd, int how)
{
SOCKET_FUNCTION(shutdown(sock, how));
}
*/
#undef socket
int
-posix_socket(int domain, int type, int protocol)
+w32_socket(int domain, int type, int protocol)
{
SOCKET sock;