diff options
author | shadchin <shadchin@yandex-team.com> | 2023-08-14 12:41:27 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2023-08-14 14:09:27 +0300 |
commit | 08b404bdafe0490fae37fad3a57df8093c46737e (patch) | |
tree | 6ce3fc3088ab3fdd5b4c1ccc119cd7aff6a80bde | |
parent | 4caad3092762e92b7d0216e2f9b9b4a0f13b389c (diff) | |
download | ydb-08b404bdafe0490fae37fad3a57df8093c46737e.tar.gz |
Update contrib/libs/postgresql to 14.8
10 files changed, 194 insertions, 27 deletions
diff --git a/contrib/libs/postgresql/src/port/pread.c b/contrib/libs/postgresql/src/port/pread.c index 486f07a7dff..a35d3f4b07c 100644 --- a/contrib/libs/postgresql/src/port/pread.c +++ b/contrib/libs/postgresql/src/port/pread.c @@ -15,7 +15,7 @@ */ -#include "postgres.h" +#include "c.h" #ifdef WIN32 #include <windows.h> diff --git a/contrib/libs/postgresql/src/port/pwrite.c b/contrib/libs/postgresql/src/port/pwrite.c index 282b27115e5..e3a132aa7aa 100644 --- a/contrib/libs/postgresql/src/port/pwrite.c +++ b/contrib/libs/postgresql/src/port/pwrite.c @@ -15,7 +15,7 @@ */ -#include "postgres.h" +#include "c.h" #ifdef WIN32 #include <windows.h> diff --git a/contrib/libs/postgresql/src/port/pwritev.c b/contrib/libs/postgresql/src/port/pwritev.c index 2e8ef7e3785..082bed9abfc 100644 --- a/contrib/libs/postgresql/src/port/pwritev.c +++ b/contrib/libs/postgresql/src/port/pwritev.c @@ -15,7 +15,7 @@ */ -#include "postgres.h" +#include "c.h" #ifdef WIN32 #include <windows.h> diff --git a/contrib/libs/postgresql/src/port/win32common.c b/contrib/libs/postgresql/src/port/win32common.c new file mode 100644 index 00000000000..2fd78f7f936 --- /dev/null +++ b/contrib/libs/postgresql/src/port/win32common.c @@ -0,0 +1,68 @@ +/*------------------------------------------------------------------------- + * + * win32common.c + * Common routines shared among the win32*.c ports. + * + * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/port/win32common.c + * + *------------------------------------------------------------------------- + */ + +#ifdef FRONTEND +#include "postgres_fe.h" +#else +#include "postgres.h" +#endif + +#ifdef WIN32 + +/* + * pgwin32_get_file_type + * + * Convenience wrapper for GetFileType() with specific error handling for all the + * port implementations. Returns the file type associated with a HANDLE. + * + * On error, sets errno with FILE_TYPE_UNKNOWN as file type. + */ +DWORD +pgwin32_get_file_type(HANDLE hFile) +{ + DWORD fileType = FILE_TYPE_UNKNOWN; + DWORD lastError; + + errno = 0; + + /* + * When stdin, stdout, and stderr aren't associated with a stream the + * special value -2 is returned: + * https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle + */ + if (hFile == INVALID_HANDLE_VALUE || hFile == (HANDLE) -2) + { + errno = EINVAL; + return FILE_TYPE_UNKNOWN; + } + + fileType = GetFileType(hFile); + lastError = GetLastError(); + + /* + * Invoke GetLastError in order to distinguish between a "valid" return of + * FILE_TYPE_UNKNOWN and its return due to a calling error. In case of + * success, GetLastError() returns NO_ERROR. + */ + if (fileType == FILE_TYPE_UNKNOWN && lastError != NO_ERROR) + { + _dosmaperr(lastError); + return FILE_TYPE_UNKNOWN; + } + + return fileType; +} + +#endif /* WIN32 */ diff --git a/contrib/libs/postgresql/src/port/win32fseek.c b/contrib/libs/postgresql/src/port/win32fseek.c new file mode 100644 index 00000000000..985313c825f --- /dev/null +++ b/contrib/libs/postgresql/src/port/win32fseek.c @@ -0,0 +1,75 @@ +/*------------------------------------------------------------------------- + * + * win32fseek.c + * Replacements for fseeko() and ftello(). + * + * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/port/win32fseek.c + * + *------------------------------------------------------------------------- + */ + +#ifdef FRONTEND +#include "postgres_fe.h" +#else +#include "postgres.h" +#endif + +#if defined(WIN32) && defined(_MSC_VER) + +/* + * _pgfseeko64 + * + * Calling fseek() on a handle to a non-seeking device such as a pipe or + * a communications device is not supported, and fseek() may not return + * an error. This wrapper relies on the file type to check which cases + * are supported. + */ +int +_pgfseeko64(FILE *stream, pgoff_t offset, int origin) +{ + DWORD fileType; + HANDLE hFile = (HANDLE) _get_osfhandle(_fileno(stream)); + + fileType = pgwin32_get_file_type(hFile); + if (errno != 0) + return -1; + + if (fileType == FILE_TYPE_DISK) + return _fseeki64(stream, offset, origin); + else if (fileType == FILE_TYPE_CHAR || fileType == FILE_TYPE_PIPE) + errno = ESPIPE; + else + errno = EINVAL; + + return -1; +} + +/* + * _pgftello64 + * + * Same as _pgfseeko64(). + */ +pgoff_t +_pgftello64(FILE *stream) +{ + DWORD fileType; + HANDLE hFile = (HANDLE) _get_osfhandle(_fileno(stream)); + + fileType = pgwin32_get_file_type(hFile); + if (errno != 0) + return -1; + + if (fileType == FILE_TYPE_DISK) + return _ftelli64(stream); + else if (fileType == FILE_TYPE_CHAR || fileType == FILE_TYPE_PIPE) + errno = ESPIPE; + else + errno = EINVAL; + + return -1; +} + +#endif /* defined(WIN32) && defined(_MSC_VER) */ diff --git a/contrib/libs/postgresql/src/port/win32stat.c b/contrib/libs/postgresql/src/port/win32stat.c index 426e01f0efa..acbf4c7e279 100644 --- a/contrib/libs/postgresql/src/port/win32stat.c +++ b/contrib/libs/postgresql/src/port/win32stat.c @@ -289,39 +289,50 @@ int _pgfstat64(int fileno, struct stat *buf) { HANDLE hFile = (HANDLE) _get_osfhandle(fileno); - BY_HANDLE_FILE_INFORMATION fiData; + DWORD fileType = FILE_TYPE_UNKNOWN; + unsigned short st_mode; - if (hFile == INVALID_HANDLE_VALUE || buf == NULL) + if (buf == NULL) { errno = EINVAL; return -1; } - /* - * Check if the fileno is a data stream. If so, unless it has been - * redirected to a file, getting information through its HANDLE will fail, - * so emulate its stat information in the most appropriate way and return - * it instead. - */ - if ((fileno == _fileno(stdin) || - fileno == _fileno(stdout) || - fileno == _fileno(stderr)) && - !GetFileInformationByHandle(hFile, &fiData)) + fileType = pgwin32_get_file_type(hFile); + if (errno != 0) + return -1; + + switch (fileType) { - memset(buf, 0, sizeof(*buf)); - buf->st_mode = _S_IFCHR; - buf->st_dev = fileno; - buf->st_rdev = fileno; - buf->st_nlink = 1; - return 0; + /* The specified file is a disk file */ + case FILE_TYPE_DISK: + return fileinfo_to_stat(hFile, buf); + + /* + * The specified file is a socket, a named pipe, or an anonymous + * pipe. + */ + case FILE_TYPE_PIPE: + st_mode = _S_IFIFO; + break; + /* The specified file is a character file */ + case FILE_TYPE_CHAR: + st_mode = _S_IFCHR; + break; + /* Unused flag and unknown file type */ + case FILE_TYPE_REMOTE: + case FILE_TYPE_UNKNOWN: + default: + errno = EINVAL; + return -1; } - /* - * Since we already have a file handle there is no need to check for - * ERROR_DELETE_PENDING. - */ - - return fileinfo_to_stat(hFile, buf); + memset(buf, 0, sizeof(*buf)); + buf->st_mode = st_mode; + buf->st_dev = fileno; + buf->st_rdev = fileno; + buf->st_nlink = 1; + return 0; } #endif /* WIN32 */ diff --git a/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt b/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt index 5f8ab9b2213..c8fe7003422 100644 --- a/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt +++ b/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt @@ -931,8 +931,10 @@ target_sources(yql-parser-pg_wrapper PRIVATE ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/pwrite.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/pwritev.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/system.c + ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32common.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32env.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32error.c + ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32fseek.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32security.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32setlocale.c ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32stat.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-linux.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-linux.h index 54680a3d722..068918eedfd 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-linux.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-linux.h @@ -620,6 +620,9 @@ /* Define to 1 if you have the <sys/ipc.h> header file. */ #define HAVE_SYS_IPC_H 1 +/* Define to 1 if you have the <sys/personality.h> header file. */ +#define HAVE_SYS_PERSONALITY_H 1 + /* Define to 1 if you have the <sys/prctl.h> header file. */ #define HAVE_SYS_PRCTL_H 1 @@ -716,6 +719,9 @@ /* Define to 1 if you have the `writev' function. */ #define HAVE_WRITEV 1 +/* Define to 1 if you have the `X509_get_signature_info' function. */ +#define HAVE_X509_GET_SIGNATURE_INFO 1 + /* Define to 1 if you have the `X509_get_signature_nid' function. */ #define HAVE_X509_GET_SIGNATURE_NID 1 diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-win.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-win.h index c1519740bed..918767b2a94 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-win.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/pg_config-win.h @@ -53,6 +53,9 @@ /* Define to 1 if you have the <sys/ipc.h> header file. */ #undef HAVE_SYS_IPC_H +/* Define to 1 if you have the <sys/personality.h> header file. */ +#undef HAVE_SYS_PERSONALITY_H + /* Define to 1 if you have the <langinfo.h> header file. */ #undef HAVE_LANGINFO_H diff --git a/ydb/library/yql/parser/pg_wrapper/ya.make b/ydb/library/yql/parser/pg_wrapper/ya.make index ca817ab0df7..5f3d1d51cb8 100644 --- a/ydb/library/yql/parser/pg_wrapper/ya.make +++ b/ydb/library/yql/parser/pg_wrapper/ya.make @@ -114,8 +114,10 @@ ELSEIF (OS_WINDOWS) ../../../../../contrib/libs/postgresql/src/port/pwrite.c ../../../../../contrib/libs/postgresql/src/port/pwritev.c ../../../../../contrib/libs/postgresql/src/port/system.c + ../../../../../contrib/libs/postgresql/src/port/win32common.c ../../../../../contrib/libs/postgresql/src/port/win32env.c ../../../../../contrib/libs/postgresql/src/port/win32error.c + ../../../../../contrib/libs/postgresql/src/port/win32fseek.c ../../../../../contrib/libs/postgresql/src/port/win32security.c ../../../../../contrib/libs/postgresql/src/port/win32setlocale.c ../../../../../contrib/libs/postgresql/src/port/win32stat.c |