postgresql/src/include/port
Michael Paquier 84fb27511d Replace off_t by pgoff_t in I/O routines
PostgreSQL's Windows port has never been able to handle files larger
than 2GB due to the use of off_t for file offsets, only 32-bit on
Windows.  This causes signed integer overflow at exactly 2^31 bytes when
trying to handle files larger than 2GB, for the routines touched by this
commit.

Note that large files are forbidden by ./configure (3c6248a828) and
meson (recent change, see 79cd66f28c).  This restriction also exists
in v16 and older versions for the now-dead MSVC scripts.

The code base already defines pgoff_t as __int64 (64-bit) on Windows for
this purpose, and some function declarations in headers use it, but many
internals still rely on off_t.  This commit switches more routines to
use pgoff_t, offering more portability, for areas mainly related to file
extensions and storage.

These are not critical for WAL segments yet, which have currently a
maximum size allowed of 1GB (well, this opens the door at allowing a
larger size for them).  This matters more for segment files if we want
to lift the large file restriction in ./configure and meson in the
future, which would make sense to remove once/if all traces of off_t are
gone from the tree.  This can additionally matter for out-of-core code
that may want files larger than 2GB in places where off_t is four bytes
in size.

Note that off_t is still used in other parts of the tree like
buffile.c, WAL sender/receiver, base backup, pg_combinebackup, etc.
These other code paths can be addressed separately, and their update
will be required if we want to remove the large file restriction in the
future.  This commit is a good first cut in itself towards more
portability, hopefully.

On Unix-like systems, pgoff_t is defined as off_t, so this change only
affects Windows behavior.

Author: Bryan Green <dbryan.green@gmail.com>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/0f238ff4-c442-42f5-adb8-01b762c94ca1@gmail.com
2025-11-13 12:41:40 +09:00
..
atomics Fix generic read and write barriers for Clang. 2025-11-08 12:26:43 +13:00
win32 Fix gai_strerror() thread-safety on Windows. 2024-02-12 11:14:21 +13:00
win32_msvc windows: msvc: Define STDIN/OUT/ERR_FILENO. 2022-07-18 17:21:54 -07:00
atomics.h Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
cygwin.h Simplify declaring variables exported from libpgcommon and libpgport. 2021-11-29 11:00:00 -05:00
darwin.h Add prefetching support on macOS 2024-08-28 07:28:27 +02:00
freebsd.h Improve the naming in wal_sync_method code. 2023-10-13 15:16:45 -05:00
linux.h Improve the naming in wal_sync_method code. 2023-10-13 15:16:45 -05:00
netbsd.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
openbsd.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
pg_bitutils.h Optimize popcount functions with ARM SVE intrinsics. 2025-03-28 16:20:20 -05:00
pg_bswap.h Grab the low-hanging fruit from forcing sizeof(Datum) to 8. 2025-08-13 17:18:22 -04:00
pg_crc32c.h Remove implicit cast from 'void *' 2025-07-02 11:51:10 +07:00
pg_iovec.h Replace off_t by pgoff_t in I/O routines 2025-11-13 12:41:40 +09:00
pg_lfind.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_numa.h Fix indentation in pg_numa code 2025-07-01 15:23:07 +02:00
pg_pthread.h IWYU widely useful pragmas 2025-01-15 18:57:53 +01:00
simd.h Optimize hex_encode() and hex_decode() using SIMD. 2025-10-06 12:28:50 -05:00
solaris.h Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
win32.h mingw: Define PGDLLEXPORT as __declspec (dllexport) as done for msvc 2022-09-30 10:50:05 -07:00
win32_port.h Replace off_t by pgoff_t in I/O routines 2025-11-13 12:41:40 +09:00
win32ntdll.h Update copyright for 2025 2025-01-01 11:21:55 -05:00