builtindir := $(datadir)/empire/builtin
einfodir := $(datadir)/empire/info.nr
ehtmldir := $(datadir)/empire/info.html
+client/w32 := sys/uio.h w32io.c w32types.h
# How to substitute Autoconf output variables
# Recursively expanded so that $@ and $< work.
ifeq ($(empthread),Windows) # really: W32, regardless of thread package
libs += lib/libw32.a
+$(client): lib/libw32.a
endif
# Cleanliness
$(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \
-C $(srcdir)/include proto.h version.h \
-C $(srcdir)/src/lib/global version.c \
+ -C $(srcdir)/src/lib $(addprefix w32/, $(client/w32)) \
-C $(srcdir)/man empire.6 \
-C $(srcdir) COPYING INSTALL install-sh
CC = @CC@
CFLAGS = @CFLAGS@ @CPPFLAGS@ @DEFS@ -I.
LDFLAGS = @LDFLAGS@
+LIBOBJS := @LIBOBJS@
LIBS = @LIBS@
E = @EXEEXT@
O = @OBJEXT@
prog = empire$E
obj = expect.$O host.$O ipglob.$O linebuf.$O login.$O main.$O play.$O \
-ringbuf.$O secure.$O servcmd.$O sysdep_w32.$O termlib.$O version.$O
+ringbuf.$O secure.$O servcmd.$O sysdep_w32.$O termlib.$O version.$O \
+$(LIBOBJS)
all: $(prog)
login.$O: misc.h sysdep_w32.h proto.h
main.$O: misc.h sysdep_w32.h version.h
play.$O: linebuf.h misc.h sysdep_w32.h proto.h ringbuf.h secure.h
-ringbuf.$O: misc.h sysdep_w32.h ringbuf.h
+ringbuf.$O: ringbuf.h
secure.$O: ringbuf.h secure.h
servcmd.$O: misc.h sysdep_w32.h proto.h secure.h
sysdep_w32.$O: misc.h sysdep_w32.h
termlib.$O: misc.h
version.$O: version.h
$(obj): config.h
+
+expect.$O: w32/w32types.h
+play.$O: w32/w32types.h
+ringbuf.$O: w32/sys/uio.h w32/w32types.h
+w32/w32io.$O: misc.h w32/sys/uio.h w32/w32types.h
### Checks for libraries.
LIBS="$LIBS_SOCKETS $LIBS"
LIB_SOCKET_NSL
+if test "$Windows_API" = yes; then
+ AC_LIBOBJ([w32/w32io])
+fi
### Checks for header files.
### Checks for typedefs, structures, and compiler characteristics.
if test "$Windows_API" = yes; then
+ CPPFLAGS="$CPPFLAGS -Iw32"
CFLAGS="$CFLAGS -mthreads"
fi
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifndef _WIN32
+#ifdef _WIN32
+#include "w32types.h"
+#else
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#else
#include <process.h>
#include <io.h>
+#include "w32types.h"
#endif
#include "linebuf.h"
#include "misc.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
-#ifndef _WIN32
#include <sys/uio.h>
-#include <unistd.h>
-#else
-#define readv(fd, iov, iovcnt) \
- w32_readv_fd((fd), (iov), (iovcnt))
-#define writev(fd, iov, iovcnt) \
- w32_writev_socket((fd), (iov), (iovcnt))
-#endif
-#include "misc.h"
#include "ringbuf.h"
/*
return result;
}
-/*
- * POSIX compatible writev() replacement specialized to sockets
- * Modelled after the GNU's libc/sysdeps/posix/writev.c
- */
-ssize_t
-w32_writev_socket(int sockfd, const struct iovec *iov, int iovcnt)
-{
- SOCKET sock = W32_FD_TO_SOCKET(sockfd);
- int i;
- 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 = send(sock, buffer, total_bytes, 0);
- free(buffer);
- if (bytes_written == SOCKET_ERROR) {
- w32_set_winsock_errno();
- return -1;
- }
- return bytes_written;
-}
-
/*
* POSIX compatible send() replacement
*/
return _close(fd);
}
-/*
- * POSIX compatible readv() replacement specialized to files.
- * Modelled after the GNU's libc/sysdeps/posix/readv.c
- */
-ssize_t
-w32_readv_fd(int fd, const struct iovec *iov, int iovcnt)
-{
- int i;
- 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)
- 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;
-}
-
#endif /* _WIN32 */
#include <ws2tcpip.h>
#include <windows.h>
-#ifdef _MSC_VER
-typedef int __w64 ssize_t;
-#endif
-
struct passwd {
char *pw_name;
};
-struct iovec {
- void *iov_base;
- size_t iov_len;
-};
-
#define W32_FD_TO_SOCKET(fd) ((SOCKET)_get_osfhandle((fd)))
#define W32_SOCKET_TO_FD(fh) (_open_osfhandle((long)(fh), O_RDWR | O_BINARY))
extern int w32_close(int fd);
extern int w32_socket(int domain, int type, int protocol);
extern int w32_connect(int sockfd, const struct sockaddr *, int addrlen);
-extern ssize_t w32_readv_fd(int fd, const struct iovec *iov,
- int iovcnt);
-extern ssize_t w32_writev_socket(int sockfd, const struct iovec *iov,
- int iovcnt);
extern struct passwd *w32_getpw(void);
extern void w32_sysdep_init(void);
#define SYS_UIO_H
#include <sys/types.h>
-#include "w32misc.h"
+#include "w32types.h"
struct iovec {
/* Base address of a memory region for input or output. */
#include <io.h>
#include <direct.h>
#include <sys/stat.h>
-
-#include "w32misc.h"
+#include "w32types.h"
/*
* w32file.c
extern char *__setstate(char *state);
extern void __srandom(unsigned seed);
-/* sys/types.h */
-#ifdef _MSC_VER
-typedef unsigned short mode_t;
-typedef long off_t;
-typedef int pid_t;
-typedef int __w64 ssize_t;
-#endif
-
/* time.h */
struct tm;
extern char *strptime(const char *buf, const char *fmt, struct tm *tm);
--- /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.
+ *
+ * ---
+ *
+ * w32types.h: POSIX emulation for WIN32, missing types
+ *
+ * Known contributors to this file:
+ * Ron Koenderink, 2007
+ * Markus Armbruster, 2009
+ */
+
+#ifndef W32TYPES_H
+#define W32TYPES_H
+
+/* sys/types.h */
+#ifdef _MSC_VER
+typedef unsigned short mode_t;
+typedef long off_t;
+typedef int pid_t;
+typedef int __w64 ssize_t;
+#endif
+
+#endif