postgresql/src
Michael Paquier a923e21631 Fix detection of unseekable files for fseek() and ftello() with MSVC
Calling fseek() or ftello() on a handle to a non-seeking device such as
a pipe or a communications device is not supported.  Unfortunately,
MSVC's flavor of these routines, _fseeki64() and _ftelli64(), do not
return an error when given a pipe as handle.  Some of the logic of
pg_dump and restore relies on these routines to check if a handle is
seekable, causing failures when passing the contents of pg_dump to
pg_restore through a pipe, for example.

This commit introduces wrappers for fseeko() and ftello() on MSVC so as
any callers are able to properly detect the cases of non-seekable
handles.  This relies mainly on GetFileType(), sharing a bit of code
with the MSVC port for fstat().  The code in charge of getting a file
type is refactored into a new file called win32common.c, shared by
win32stat.c and the new win32fseek.c.  It includes the MSVC ports for
fseeko() and ftello().

Like 765f5df, this is backpatched down to 14, where the fstat()
implementation for MSVC is able to understand about files larger than
4GB in size.  Using a TAP test for that is proving to be tricky as
IPC::Run handles the pipes by itself, still I have been able to check
the fix manually.

Reported-by: Daniel Watzinger
Author: Juan José Santamaría Flecha, Michael Paquier
Discussion: https://postgr.es/m/CAC+AXB26a4EmxM2suXxPpJaGrqAdxracd7hskLg-zxtPB50h7A@mail.gmail.com
Backpatch-through: 14
2023-04-12 09:09:38 +09:00
..
backend Refine the guidelines for rmgrdesc authors. 2023-04-11 15:26:24 -07:00
bin Introduce PG_IO_ALIGN_SIZE and align all I/O buffers. 2023-04-08 16:34:50 +12:00
common Introduce PG_IO_ALIGN_SIZE and align all I/O buffers. 2023-04-08 16:34:50 +12:00
fe_utils Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
include Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:38 +09:00
interfaces Revert "Add support for Kerberos credential delegation" 2023-04-08 07:21:35 -04:00
makefiles meson: Make auto the default of the ssl option 2023-03-13 07:04:11 +01:00
pl Add a way to get the current function's OID in pl/pgsql. 2023-04-04 13:33:18 -04:00
port Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:38 +09:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test 035_standby_logical_decoding: Add missing waits for replication 2023-04-11 11:17:36 -07:00
timezone Fix outdated references to guc.c 2023-03-02 13:49:39 +01:00
tools Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:38 +09:00
tutorial Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
.gitignore
DEVELOPERS
Makefile Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
Makefile.global.in pg_regress: Emit TAP compliant output 2023-03-31 13:00:02 +02:00
Makefile.shlib autoconf: Rely on ar supporting index creation 2022-10-07 11:53:39 -07:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00