From 759e11e81c6c17171ca8c63383df1b94568faa76 Mon Sep 17 00:00:00 2001 From: Rod Widdowson Date: Sun, 23 Jan 2011 14:29:51 +0000 Subject: [PATCH] Windows: fix parameters and return value from nt_seek SetFilePointerEx takes specific values (FILE_BEGIN/FILE_CURRENT/FILE_END) whilse fseek requires SEEK_SET, SEK_END, SEEK_CUR. It turns out that these overlap, but we should not let that pass unchallenged. SetFilePointerEx returns nonzero for success zero for failure. fseek returns the other way around. Neither of these changes currently matter, but we should fix them. Reviewed-on: http://gerrit.openafs.org/3746 Reviewed-by: Andrew Deason Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman (cherry picked from commit 4f838b03bbf9ea0e1ede8a188ea6dde3efb4e231) Change-Id: I295d172e8f14bc50facf38f08e3dc3af02b7404b Reviewed-on: http://gerrit.openafs.org/3864 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/vol/ntops.c | 21 ++++++++++++++++++--- src/vol/ntops.h | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/vol/ntops.c b/src/vol/ntops.c index 3e15ea408..b9c08e6fc 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -321,15 +321,30 @@ nt_fsync(FD_t fd) int -nt_seek(FD_t fd, afs_foff_t off, int where) +nt_seek(FD_t fd, afs_foff_t off, int whence) { int code; LARGE_INTEGER offset; - + int where; + + if (SEEK_SET == whence) { + where = FILE_BEGIN; + } else if (SEEK_END == whence) { + where = FILE_END; + } else if (SEEK_CUR == whence) { + where = FILE_CURRENT; + } else { + errno = EINVAL; + return -1; + } offset.QuadPart = off; code = SetFilePointerEx(fd, offset, NULL, where); - return code; + if (0 == code) { + errno = nterr_nt2unix(GetLastError(), EBADF); + return -1; + } + return 0; } /* nt_DevToDrive diff --git a/src/vol/ntops.h b/src/vol/ntops.h index 666197910..e50b2e0fd 100644 --- a/src/vol/ntops.h +++ b/src/vol/ntops.h @@ -34,7 +34,7 @@ extern int nt_setFileCreationTime(FD_t fd, FILETIME * ftime); extern int nt_sync(int cdrive); extern int nt_ftruncate(FD_t fd, afs_foff_t len); extern int nt_fsync(FD_t fd); -extern int nt_seek(FD_t fd, afs_foff_t off, int where); +extern int nt_seek(FD_t fd, afs_foff_t off, int whence); extern FILE *nt_fdopen(IHandle_t * h, char *fdperms); extern int nt_unlink(char *name); -- 2.39.5