Skip to content

Commit af109e3

Browse files
committed
Provide 64-bit ftruncate() and lseek() on Windows.
Change our ftruncate() macro to use the 64-bit variant of chsize(), and add a new macro to redirect lseek() to _lseeki64(). Back-patch to all supported releases, in preparation for a bug fix. Tested-by: Davinder Singh <davinder.singh@enterprisedb.com> Discussion: https://postgr.es/m/CAKZiRmyM4YnokK6Oenw5JKwAQ3rhP0YTz2T-tiw5dAQjGRXE3Q%40mail.gmail.com
1 parent 45aef9f commit af109e3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/include/port.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,33 @@ extern bool rmtree(const char *path, bool rmtopdir);
306306

307307
#if defined(WIN32) && !defined(__CYGWIN__)
308308

309+
/*
310+
* We want the 64-bit variant of lseek().
311+
*
312+
* For Visual Studio, this must be after <io.h> to avoid messing up its
313+
* lseek() and _lseeki64() function declarations.
314+
*
315+
* For MinGW there is already a macro, so we have to undefine it (depending on
316+
* _FILE_OFFSET_BITS, it may point at its own lseek64, but we don't want to
317+
* count on that being set).
318+
*/
319+
#undef lseek
320+
#define lseek(a,b,c) _lseeki64((a),(b),(c))
321+
322+
/*
323+
* We want the 64-bit variant of chsize(). It sets errno and also returns it,
324+
* so convert non-zero result to -1 to match POSIX.
325+
*
326+
* Prevent MinGW from declaring functions, and undefine its macro before we
327+
* define our own.
328+
*/
329+
#ifndef _MSC_VER
330+
#define FTRUNCATE_DEFINED
331+
#include <unistd.h>
332+
#undef ftruncate
333+
#endif
334+
#define ftruncate(a,b) (_chsize_s((a),(b)) == 0 ? 0 : -1)
335+
309336
/*
310337
* open() and fopen() replacements to allow deletion of open files and
311338
* passing of other special options.

src/include/port/win32_port.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
/* Must be here to avoid conflicting with prototype in windows.h */
8080
#define mkdir(a,b) mkdir(a)
8181

82-
#define ftruncate(a,b) chsize(a,b)
83-
8482
/* Windows doesn't have fsync() as such, use _commit() */
8583
#define fsync(fd) _commit(fd)
8684

src/pl/plperl/plperl_system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
#undef fstat
110110
#undef kill
111111
#undef listen
112+
#undef lseek
112113
#undef lstat
113114
#undef mkdir
114115
#undef open

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy