1
0
forked from 0ad/0ad

fixed file sharing + open mode bug

This was SVN commit r626.
This commit is contained in:
janwas 2004-07-05 02:26:04 +00:00
parent 2914b616c7
commit 85b0e120af

View File

@ -359,39 +359,43 @@ int aio_assign_handle(uintptr_t handle)
// open fn in async mode; associate with fd (retrieve via aio_h(fd)) // open fn in async mode; associate with fd (retrieve via aio_h(fd))
int aio_open(const char* fn, int mode, int fd) int aio_reopen(int fd, const char* fn, int oflag, ...)
{ {
// interpret mode // interpret oflag
DWORD access = GENERIC_READ; // assume O_RDONLY DWORD access = GENERIC_READ; // assume O_RDONLY
DWORD share = 0; DWORD share = FILE_SHARE_READ;
if(mode & O_WRONLY)
access = GENERIC_WRITE;
else if(mode & O_RDWR)
access = GENERIC_READ|GENERIC_WRITE;
else
share = FILE_SHARE_READ;
DWORD create = OPEN_EXISTING; DWORD create = OPEN_EXISTING;
if(mode & O_CREAT) if(oflag & O_WRONLY)
create = (mode & O_EXCL)? CREATE_NEW : CREATE_ALWAYS; {
DWORD flags = FILE_FLAG_OVERLAPPED|FILE_FLAG_NO_BUFFERING|FILE_FLAG_SEQUENTIAL_SCAN; access = GENERIC_WRITE;
share = FILE_SHARE_WRITE;
}
else if(oflag & O_RDWR)
{
access |= GENERIC_WRITE;
share |= FILE_SHARE_WRITE;
}
if(oflag & O_CREAT)
create = (oflag & O_EXCL)? CREATE_NEW : CREATE_ALWAYS;
// open file // open file
DWORD flags = FILE_FLAG_OVERLAPPED|FILE_FLAG_NO_BUFFERING|FILE_FLAG_SEQUENTIAL_SCAN;
HANDLE h = CreateFile(fn, access, share, 0, create, flags, 0); HANDLE h = CreateFile(fn, access, share, 0, create, flags, 0);
if(h == INVALID_HANDLE_VALUE) if(h == INVALID_HANDLE_VALUE)
{ {
fail:
debug_warn("aio_open failed"); debug_warn("aio_open failed");
return -1; return -1;
} }
if(aio_h_set(fd, h) < 0) if(aio_h_set(fd, h) < 0)
{ {
debug_warn("aio_open failed");
CloseHandle(h); CloseHandle(h);
return -1; goto fail;
} }
#ifdef PARANOIA #ifdef PARANOIA
debug_out("aio_open fn=%s fd=%d\n", fn, fd); debug_out("aio_reopen fd=%d fn=%s\n", fd, fn);
#endif #endif
return 0; return 0;