Don't fake open() and fcntl() just for ef_open()
Put the Windows code into new open_locked() instead. It's ugly having that in file.c, but the fakes are ugly too, and somewhat brittle. Remove posix_open(), F_SETLK, F_RDLCK, F_WRLCK, struct flock, and simplify fcntl().
This commit is contained in:
parent
c665c83ba4
commit
dbef646f5d
4 changed files with 40 additions and 62 deletions
|
@ -45,9 +45,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <share.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
* Need to include winsock2.h before ws2tcpip.h.
|
||||
|
@ -279,32 +277,6 @@ posix_close(int fd)
|
|||
return _close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* POSIX equivalent for open().
|
||||
* Implements file locks when opening files to provide equivalent
|
||||
* F_GETLK/F_SETLK.
|
||||
*/
|
||||
int
|
||||
posix_open(const char *fname, int oflag, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int pmode = 0;
|
||||
|
||||
if (oflag & O_CREAT) {
|
||||
va_start(ap, oflag);
|
||||
pmode = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't implement fcntl() for F_SETLK. Instead, we lock *all*
|
||||
* files we open. Not ideal, but it works for Empire.
|
||||
*/
|
||||
return _sopen(fname, oflag,
|
||||
oflag & O_RDONLY ? SH_DENYNO : SH_DENYWR,
|
||||
pmode);
|
||||
}
|
||||
|
||||
/*
|
||||
* POSIX equivalent for read().
|
||||
*/
|
||||
|
@ -429,7 +401,6 @@ writev(int fd, const struct iovec *iov, int iovcnt)
|
|||
* Horrible hacks, just good enough support Empire's use of fcntl().
|
||||
* F_GETFL / F_SETFL support making a socket (non-)blocking by getting
|
||||
* flags, adding or removing O_NONBLOCK, and setting the result.
|
||||
* F_SETLK does nothing. Instead, we lock in posix_open().
|
||||
*/
|
||||
int
|
||||
fcntl(int fd, int cmd, ...)
|
||||
|
@ -455,8 +426,6 @@ fcntl(int fd, int cmd, ...)
|
|||
return -1;
|
||||
}
|
||||
return 0;
|
||||
case F_SETLK:
|
||||
return 0;
|
||||
}
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue