postgresql/src
Michael Paquier 5c32549460 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:53 +09:00
..
backend Fix ts_headline() edge cases for empty query and empty search text. 2023-04-06 15:52:37 -04:00
bin Fix pg_dump for hash partitioning on enum columns. 2023-03-17 13:31:40 -04:00
common Fix JSON error reporting for many cases of erroneous string values. 2023-03-13 15:19:00 -04:00
fe_utils Use correct connection for cancellation in frontend's parallel slots 2022-08-27 15:22:07 +09:00
include Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:53 +09:00
interfaces Fix inconsistent error handling for GSS encryption in PQconnectPoll() 2023-03-13 16:36:28 +09:00
makefiles Refactor DLSUFFIX handling 2022-03-25 08:56:02 +01:00
pl Add missing support for the latest SPI status codes. 2023-02-22 13:24:51 +00:00
port Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:53 +09:00
template On NetBSD, force dynamic symbol resolution at postmaster start. 2022-08-30 17:28:55 -04:00
test For Kerberos testing, disable DNS lookups 2023-04-07 19:36:25 -04:00
timezone Update time zone data files to tzdata release 2022g. 2023-01-31 17:37:06 -05:00
tools Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:53 +09:00
tutorial Doc: sync src/tutorial/basics.source with SGML documentation. 2022-11-19 13:09:14 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Prevent port collisions between concurrent TAP tests 2022-11-22 10:51:13 -05:00
Makefile.shlib AIX: Fix missing libpq symbols by respecting SHLIB_EXPORTS. 2021-09-06 11:27:59 -07:00
nls-global.mk Improve frontend error logging style. 2022-04-08 14:55:14 -04:00