Simple POSIX I/O emulation layer to work around Windows's defective
Unix I/O: [_WIN32] (socklen_t, accept, posix_accept, bind. posix_bind, listen) (posix_listen, setsockopt, posix_setsockopt, shutdown, posix_shutdown) (socket, posix_socket, close, posix_close, creat, fstat, posix_fstat) (lseek, posix_lseek, open, posix_open, read, posix_read, write) (posix_write, fileno, posix_fileno, fcntl, O_NONBLOCK, F_RDLCK) (F_WRLCK, F_GETFL, F_SETFL, F_SETLK, EWOULDBLOCK, ENOTSOCK) (flock, fsync, posix_fsync): New. (ef_open, io_close, io_input, io_output, io_shutdown, io_noblocking) (player_accept): Use them to simplify. [_WIN32] (posix_fd2socket): New. (empth_select): Use it. (gen_power): Use it.
This commit is contained in:
parent
e7b04123a9
commit
4bbc3f4286
17 changed files with 669 additions and 109 deletions
|
@ -36,17 +36,11 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#include <share.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "file.h"
|
||||
#include "match.h"
|
||||
#include "misc.h"
|
||||
|
@ -68,9 +62,7 @@ int
|
|||
ef_open(int type, int how)
|
||||
{
|
||||
struct empfile *ep;
|
||||
#if !defined(_WIN32)
|
||||
struct flock lock;
|
||||
#endif
|
||||
int oflags, fd, fsiz, size;
|
||||
|
||||
if (ef_check(type) < 0)
|
||||
|
@ -89,13 +81,7 @@ ef_open(int type, int how)
|
|||
oflags |= O_CREAT | O_TRUNC;
|
||||
#if defined(_WIN32)
|
||||
oflags |= O_BINARY;
|
||||
if ((fd = sopen(ep->file, oflags,
|
||||
how & EFF_RDONLY ? SH_DENYNO : SH_DENYWR,
|
||||
S_IRWUG)) < 0) {
|
||||
logerror("Can't open %s (%s)", ep->file, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
if ((fd = open(ep->file, oflags, S_IRWUG)) < 0) {
|
||||
logerror("Can't open %s (%s)", ep->file, strerror(errno));
|
||||
return 0;
|
||||
|
@ -109,7 +95,6 @@ ef_open(int type, int how)
|
|||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* get file size */
|
||||
fsiz = fsize(fd);
|
||||
|
|
|
@ -37,9 +37,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
|
|
|
@ -33,12 +33,7 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#endif
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
|
|
|
@ -35,13 +35,8 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "file.h"
|
||||
#include "game.h"
|
||||
#include "misc.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue