aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-08-14 12:41:27 +0300
committershadchin <shadchin@yandex-team.com>2023-08-14 14:09:27 +0300
commit08b404bdafe0490fae37fad3a57df8093c46737e (patch)
tree6ce3fc3088ab3fdd5b4c1ccc119cd7aff6a80bde /contrib
parent4caad3092762e92b7d0216e2f9b9b4a0f13b389c (diff)
downloadydb-08b404bdafe0490fae37fad3a57df8093c46737e.tar.gz
Update contrib/libs/postgresql to 14.8
Diffstat (limited to 'contrib')
-rw-r--r--contrib/libs/postgresql/src/port/pread.c2
-rw-r--r--contrib/libs/postgresql/src/port/pwrite.c2
-rw-r--r--contrib/libs/postgresql/src/port/pwritev.c2
-rw-r--r--contrib/libs/postgresql/src/port/win32common.c68
-rw-r--r--contrib/libs/postgresql/src/port/win32fseek.c75
-rw-r--r--contrib/libs/postgresql/src/port/win32stat.c59
6 files changed, 181 insertions, 27 deletions
diff --git a/contrib/libs/postgresql/src/port/pread.c b/contrib/libs/postgresql/src/port/pread.c
index 486f07a7df..a35d3f4b07 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 282b27115e..e3a132aa7a 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 2e8ef7e378..082bed9abf 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 0000000000..2fd78f7f93
--- /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 0000000000..985313c825
--- /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 426e01f0ef..acbf4c7e27 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 */