/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * 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
* ---
*
* posixio.c: POSIX IO emulation layer for WIN32
- *
+ *
* Known contributors to this file:
* Ron Koenderink, 2007
+ * Markus Armbruster, 2007-2008
*/
/*
#include <share.h>
#include <stdio.h>
#include <stdarg.h>
+/*
+ * Need to include winsock2.h before ws2tcpip.h.
+ * Use sys/socket.h to ensure the #undef NS_ALL
+ * is not missed after including winsock2.h.
+ */
#include "sys/socket.h"
#include <sys/stat.h>
#include <ws2tcpip.h>
{
SOCKET handle;
int new_fd;
-
+
if ((new_fd = get_fd()) < 0)
return -1;
FILE_FUNCTION(FDMAP_IO_FILE, _commit(handle))
}
+/*
+ * POSIX ftruncate()
+ */
+int
+ftruncate(int fd, off_t length)
+{
+ FILE_FUNCTION(FDMAP_IO_FILE, _chsize(handle, length))
+}
+
/*
* POSIX equivalent for fstat().
* fstat() is used instead of _fstat(),
}
buffer = malloc(total_bytes);
- if (buffer == NULL && total_bytes != 0)
+ if (buffer == NULL && total_bytes != 0) {
+ errno = ENOMEM;
return -1;
+ }
bytes_read = posix_read(fd, buffer, total_bytes);
if (bytes_read <= 0) {
total_bytes += iov[i].iov_len;
buffer = malloc(total_bytes);
- if (buffer == NULL && total_bytes != 0)
+ if (buffer == NULL && total_bytes != 0) {
+ errno = ENOMEM;
return -1;
+ }
buffer_location = buffer;
for (i = 0; i < iovcnt; i++) {
if (type == FDMAP_IO_SOCKET) {
result = WSAIoctl(handle, FIONBIO, NULL, 0,&nonblocking,
sizeof (nonblocking), &bytes_returned, NULL, NULL);
-
+
if(result < 0) {
errno = WSAGetLastError();
return -1;