From: Thomas Munro Date: Fri, 6 Jan 2023 03:38:46 +0000 (+1300) Subject: Fix pg_truncate() on Windows. X-Git-Tag: REL_15_2~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f60acde869985b35146c6f7f941dd571fc88b3c4;p=thirdparty%2Fpostgresql.git Fix pg_truncate() on Windows. Commit 57faaf376 added pg_truncate(const char *path, off_t length), but "length" was ignored under WIN32 and the file was unconditionally truncated to 0. There was no live bug, since the only caller passes 0. Fix, and back-patch to 14 where the function arrived. Author: Justin Pryzby Discussion: https://postgr.es/m/20230106031652.GR3109%40telsasoft.com --- diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 24704b6a023..8d7ef91785e 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -649,7 +649,7 @@ pg_truncate(const char *path, off_t length) fd = OpenTransientFile(path, O_RDWR | PG_BINARY); if (fd >= 0) { - ret = ftruncate(fd, 0); + ret = ftruncate(fd, length); save_errno = errno; CloseTransientFile(fd); errno = save_errno;