--- libeio/eio.c 2012/04/24 18:47:50 1.120 +++ libeio/eio.c 2012/10/09 04:53:53 1.123 @@ -134,6 +134,41 @@ #define statvfs(path,buf) EIO_ENOSYS () #define fstatvfs(fd,buf) EIO_ENOSYS () + #define pread(fd,buf,count,offset) eio__pread (fd, buf, count, offset) + #define pwrite(fd,buf,count,offset) eio__pwrite (fd, buf, count, offset) + + #if __GNUC__ + typedef long long eio_off_t; /* signed for compatibility to msvc */ + #else + typedef __int64 eio_off_t; /* unsigned not supported by msvc */ + #endif + + static eio_ssize_t + eio__pread (int fd, void *buf, eio_ssize_t count, eio_off_t offset) + { + OVERLAPPED o = { 0 }; + DWORD got; + + o.Offset = offset; + o.OffsetHigh = offset >> 32; + + return ReadFile ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd), buf, count, &got, &o) + ? got : -1; + } + + static eio_ssize_t + eio__pwrite (int fd, void *buf, eio_ssize_t count, eio_off_t offset) + { + OVERLAPPED o = { 0 }; + DWORD got; + + o.Offset = offset; + o.OffsetHigh = offset >> 32; + + return WriteFile ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd), buf, count, &got, &o) + ? got : -1; + } + /* rename() uses MoveFile, which fails to overwrite */ #define rename(old,neu) eio__rename (old, neu) @@ -381,15 +416,6 @@ static xmutex_t reqlock; static xcond_t reqwait; -#if !HAVE_PREADWRITE -/* - * make our pread/pwrite emulation safe against themselves, but not against - * normal read/write by using a mutex. slows down execution a lot, - * but that's your problem, not mine. - */ -static xmutex_t preadwritelock; -#endif - typedef struct etp_worker { struct tmpbuf tmpbuf; @@ -945,45 +971,6 @@ /*****************************************************************************/ /* work around various missing functions */ -#if !HAVE_PREADWRITE -# undef pread -# undef pwrite -# define pread eio__pread -# define pwrite eio__pwrite - -static eio_ssize_t -eio__pread (int fd, void *buf, size_t count, off_t offset) -{ - eio_ssize_t res; - off_t ooffset; - - X_LOCK (preadwritelock); - ooffset = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - res = read (fd, buf, count); - lseek (fd, ooffset, SEEK_SET); - X_UNLOCK (preadwritelock); - - return res; -} - -static eio_ssize_t -eio__pwrite (int fd, void *buf, size_t count, off_t offset) -{ - eio_ssize_t res; - off_t ooffset; - - X_LOCK (preadwritelock); - ooffset = lseek (fd, 0, SEEK_CUR); - lseek (fd, offset, SEEK_SET); - res = write (fd, buf, count); - lseek (fd, ooffset, SEEK_SET); - X_UNLOCK (preadwritelock); - - return res; -} -#endif - #ifndef HAVE_UTIMES # undef utimes @@ -1933,31 +1920,31 @@ #endif #ifdef DT_CHR case DT_CHR: ent->type = EIO_DT_CHR; break; - #endif + #endif #ifdef DT_MPC case DT_MPC: ent->type = EIO_DT_MPC; break; - #endif + #endif #ifdef DT_DIR case DT_DIR: ent->type = EIO_DT_DIR; break; - #endif + #endif #ifdef DT_NAM case DT_NAM: ent->type = EIO_DT_NAM; break; - #endif + #endif #ifdef DT_BLK case DT_BLK: ent->type = EIO_DT_BLK; break; - #endif + #endif #ifdef DT_MPB case DT_MPB: ent->type = EIO_DT_MPB; break; - #endif + #endif #ifdef DT_REG case DT_REG: ent->type = EIO_DT_REG; break; - #endif + #endif #ifdef DT_NWK case DT_NWK: ent->type = EIO_DT_NWK; break; - #endif + #endif #ifdef DT_CMP case DT_CMP: ent->type = EIO_DT_CMP; break; - #endif + #endif #ifdef DT_LNK case DT_LNK: ent->type = EIO_DT_LNK; break; #endif @@ -2242,6 +2229,8 @@ X_LOCK (wrklock); etp_worker_free (self); X_UNLOCK (wrklock); + + return 0; } /*****************************************************************************/ @@ -2249,10 +2238,6 @@ int ecb_cold eio_init (void (*want_poll)(void), void (*done_poll)(void)) { -#if !HAVE_PREADWRITE - X_MUTEX_CREATE (preadwritelock); -#endif - return etp_init (want_poll, done_poll); } @@ -2262,7 +2247,7 @@ free (req); } -#define REQ(rtype) \ +#define REQ(rtype) \ eio_req *req; \ \ req = (eio_req *)calloc (1, sizeof *req); \