--------------------- PatchSet 6716 Date: 2005/07/10 08:56:32 Author: serassio Branch: nt-2_5 Tag: (none) Log: Allow Squid 2.5 to run again on Windows NT 4: - Changed emulated truncate() to use the more available SetFilePointer() instead of SetFilePointerEx() - Removed the usage and the build of truncate() when USE_TRUNCATE is defined Members: lib/win32lib.c:1.1.32.17->1.1.32.18 src/fs/awin32/aiops.c:1.1.62.17->1.1.62.18 src/fs/awin32/async_io.c:1.1.62.9->1.1.62.10 Index: squid/lib/win32lib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/win32lib.c,v retrieving revision 1.1.32.17 retrieving revision 1.1.32.18 diff -u -r1.1.32.17 -r1.1.32.18 --- squid/lib/win32lib.c 25 Apr 2005 14:06:08 -0000 1.1.32.17 +++ squid/lib/win32lib.c 10 Jul 2005 08:56:32 -0000 1.1.32.18 @@ -1,5 +1,5 @@ /* - * $Id: win32lib.c,v 1.1.32.17 2005/04/25 14:06:08 serassio Exp $ + * $Id: win32lib.c,v 1.1.32.18 2005/07/10 08:56:32 serassio Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -334,60 +334,71 @@ return 0; } +#if USE_TRUNCATE int WIN32_ftruncate (int fd, off_t size) { - HANDLE hfile; - LARGE_INTEGER li; - BOOL result; - LARGE_INTEGER zero; + HANDLE file; + DWORD error; + LARGE_INTEGER size64; + LARGE_INTEGER test64; - if (fd < 0) + if (fd < 0) { + errno = EBADF; return -1; - - li.QuadPart = (__int64)size; - zero.QuadPart = 0; - - hfile = (HANDLE) _get_osfhandle (fd); - result = SetFilePointerEx(hfile, zero, NULL, FILE_CURRENT); - if (result == 0 - || SetFilePointerEx(hfile, li, NULL, FILE_BEGIN) == 0 - || !SetEndOfFile(hfile)) - { - int error = GetLastError (); + } - switch (error) - { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } + size64.QuadPart = (__int64)size; + test64.QuadPart = 0; - return -1; + file = (HANDLE)_get_osfhandle(fd); + + /* Get current file position to check File Handle */ + test64.LowPart = SetFilePointer(file, test64.LowPart, &test64.HighPart, FILE_CURRENT); + if ((test64.LowPart == INVALID_SET_FILE_POINTER) && ((error = GetLastError()) != NO_ERROR)) + goto WIN32_ftruncate_error; + + /* Set the current File Pointer position */ + size64.LowPart = SetFilePointer(file, size64.LowPart, &size64.HighPart, FILE_BEGIN); + if ((size64.LowPart == INVALID_SET_FILE_POINTER) && ((error = GetLastError()) != NO_ERROR)) + goto WIN32_ftruncate_error; + else if (!SetEndOfFile(file)) { + int error = GetLastError (); + goto WIN32_ftruncate_error; } return 0; + +WIN32_ftruncate_error: + switch (error) + { + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + default: + errno = EIO; + break; + } + + return -1; } int WIN32_truncate (const char *pathname, off_t length) { - int fd; - int res = -1; + int fd; + int res = -1; - fd = open (pathname, O_RDWR); + fd = open(pathname, O_RDWR); - if (fd == -1) - errno=EBADF; - else - { - res = WIN32_ftruncate (fd, length); - _close (fd); + if (fd == -1) + errno = EBADF; + else { + res = WIN32_ftruncate(fd, length); + _close(fd); } - return res; + return res; } +#endif static struct _wsaerrtext { int err; Index: squid/src/fs/awin32/aiops.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/aiops.c,v retrieving revision 1.1.62.17 retrieving revision 1.1.62.18 diff -u -r1.1.62.17 -r1.1.62.18 --- squid/src/fs/awin32/aiops.c 20 Mar 2005 10:24:26 -0000 1.1.62.17 +++ squid/src/fs/awin32/aiops.c 10 Jul 2005 08:56:32 -0000 1.1.62.18 @@ -1,5 +1,5 @@ /* - * $Id: aiops.c,v 1.1.62.17 2005/03/20 10:24:26 serassio Exp $ + * $Id: aiops.c,v 1.1.62.18 2005/07/10 08:56:32 serassio Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -124,7 +124,9 @@ static void squidaio_do_close(squidaio_request_t *); static void squidaio_do_stat(squidaio_request_t *); static void squidaio_do_unlink(squidaio_request_t *); +#if USE_TRUNCATE static void squidaio_do_truncate(squidaio_request_t *); +#endif #if AIO_OPENDIR static void *squidaio_do_opendir(squidaio_request_t *); #endif @@ -495,9 +497,11 @@ case _AIO_OP_UNLINK: squidaio_do_unlink(request); break; +#if USE_TRUNCATE case _AIO_OP_TRUNCATE: squidaio_do_truncate(request); break; +#endif #if AIO_OPENDIR /* Opendir not implemented yet */ case _AIO_OP_OPENDIR: squidaio_do_opendir(request); @@ -864,6 +868,8 @@ requestp->err = errno; } + +#if USE_TRUNCATE int squidaio_truncate(const char *path, off_t length, squidaio_result_t * resultp) { @@ -887,6 +893,7 @@ requestp->ret = truncate(requestp->path, requestp->offset); requestp->err = errno; } +#endif #if AIO_OPENDIR Index: squid/src/fs/awin32/async_io.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/async_io.c,v retrieving revision 1.1.62.9 retrieving revision 1.1.62.10 diff -u -r1.1.62.9 -r1.1.62.10 --- squid/src/fs/awin32/async_io.c 30 Mar 2005 07:59:43 -0000 1.1.62.9 +++ squid/src/fs/awin32/async_io.c 10 Jul 2005 08:56:32 -0000 1.1.62.10 @@ -1,6 +1,6 @@ /* - * $Id: async_io.c,v 1.1.62.9 2005/03/30 07:59:43 serassio Exp $ + * $Id: async_io.c,v 1.1.62.10 2005/07/10 08:56:32 serassio Exp $ * * DEBUG: section 32 Asynchronous Disk I/O * AUTHOR: Pete Bentley @@ -268,6 +268,7 @@ dlinkAdd(ctrlp, &ctrlp->node, &used_list); } /* aioUnlink */ +#if USE_TRUNCATE void aioTruncate(const char *path, off_t length, AIOCB * callback, void *callback_data) { @@ -284,6 +285,7 @@ squidaio_truncate(path, length, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); } /* aioTruncate */ +#endif int