aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2025-01-09 12:10:26 +1300
committerThomas Munro <tmunro@postgresql.org>2025-01-09 14:57:52 +1300
commit1636c5e56ed72e53127fc4cb0095422d9a0d250a (patch)
tree9f75f1f83d9f1071011af48c889c406c0e9c87d4 /src
parent049c8cb9a239c9b7136174eb038fc7cd902b487e (diff)
downloadpostgresql-1636c5e56ed72e53127fc4cb0095422d9a0d250a.tar.gz
postgresql-1636c5e56ed72e53127fc4cb0095422d9a0d250a.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/include/port.h27
-rw-r--r--src/include/port/win32_port.h2
-rw-r--r--src/pl/plperl/plperl_system.h1
3 files changed, 28 insertions, 2 deletions
diff --git a/src/include/port.h b/src/include/port.h
index da18268d17d..3a2601fdc01 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -294,6 +294,33 @@ extern bool rmtree(const char *path, bool rmtopdir);
#if defined(WIN32) && !defined(__CYGWIN__)
/*
+ * We want the 64-bit variant of lseek().
+ *
+ * For Visual Studio, this must be after <io.h> to avoid messing up its
+ * lseek() and _lseeki64() function declarations.
+ *
+ * For MinGW there is already a macro, so we have to undefine it (depending on
+ * _FILE_OFFSET_BITS, it may point at its own lseek64, but we don't want to
+ * count on that being set).
+ */
+#undef lseek
+#define lseek(a,b,c) _lseeki64((a),(b),(c))
+
+/*
+ * We want the 64-bit variant of chsize(). It sets errno and also returns it,
+ * so convert non-zero result to -1 to match POSIX.
+ *
+ * Prevent MinGW from declaring functions, and undefine its macro before we
+ * define our own.
+ */
+#ifndef _MSC_VER
+#define FTRUNCATE_DEFINED
+#include <unistd.h>
+#undef ftruncate
+#endif
+#define ftruncate(a,b) (_chsize_s((a),(b)) == 0 ? 0 : -1)
+
+/*
* open() and fopen() replacements to allow deletion of open files and
* passing of other special options.
*/
diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h
index 9ca80e574e9..be3af013368 100644
--- a/src/include/port/win32_port.h
+++ b/src/include/port/win32_port.h
@@ -62,8 +62,6 @@
/* Must be here to avoid conflicting with prototype in windows.h */
#define mkdir(a,b) mkdir(a)
-#define ftruncate(a,b) chsize(a,b)
-
/* Windows doesn't have fsync() as such, use _commit() */
#define fsync(fd) _commit(fd)
diff --git a/src/pl/plperl/plperl_system.h b/src/pl/plperl/plperl_system.h
index 61550db2a5d..96cb217d104 100644
--- a/src/pl/plperl/plperl_system.h
+++ b/src/pl/plperl/plperl_system.h
@@ -109,6 +109,7 @@
#undef fstat
#undef kill
#undef listen
+#undef lseek
#undef lstat
#undef mkdir
#undef open