summaryrefslogtreecommitdiff
path: root/src/include/port.h
diff options
context:
space:
mode:
authorThomas Munro2025-01-08 23:10:26 +0000
committerThomas Munro2025-01-09 02:00:58 +0000
commit026762dae39d6efcbfa99a18a15fdfeecbd5b9cc (patch)
tree183c068e7778696618b640b608e1427b74c1a22a /src/include/port.h
parent229e7793d96954739d3fb9b37e2ccf77c2803f07 (diff)
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 <[email protected]> Discussion: https://postgr.es/m/CAKZiRmyM4YnokK6Oenw5JKwAQ3rhP0YTz2T-tiw5dAQjGRXE3Q%40mail.gmail.com
Diffstat (limited to 'src/include/port.h')
-rw-r--r--src/include/port.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/include/port.h b/src/include/port.h
index d2409a43e33..818b7c7baef 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -307,6 +307,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.
*/