From 05b343edd8581d797522051f1e903063429d6601 Mon Sep 17 00:00:00 2001 From: Kartik Naik Date: Mon, 10 Aug 2026 18:13:42 +0530 Subject: merge the ftruncate shim into posix_win.c ftruncate was the only fd shim that passed its descriptor to the CRT without stripping the posix_open() tag bit, so _chsize() rejected the negative fd with EBADF and the truncation failed. Move the shim into posix_win.c so it can use get_real_fd() like fstat, close, read and write, and drop the build glue for the separate ftruncate.c. --- crypto/CMakeLists.txt | 4 ---- crypto/Makefile.am | 4 ---- crypto/compat/ftruncate.c | 17 ----------------- crypto/compat/posix_win.c | 8 ++++++++ 4 files changed, 8 insertions(+), 25 deletions(-) delete mode 100644 crypto/compat/ftruncate.c (limited to 'crypto') diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 491b9b4..0698ab4 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -637,10 +637,6 @@ if(NOT HAVE_FREEZERO) set(COMPAT_SRC ${COMPAT_SRC} compat/freezero.c) endif() -if(NOT HAVE_FTRUNCATE) - set(COMPAT_SRC ${COMPAT_SRC} compat/ftruncate.c) -endif() - if(NOT HAVE_GETDELIM) set(COMPAT_SRC ${COMPAT_SRC} compat/getdelim.c) endif() diff --git a/crypto/Makefile.am b/crypto/Makefile.am index f703e33..7969aee 100644 --- a/crypto/Makefile.am +++ b/crypto/Makefile.am @@ -148,10 +148,6 @@ if !HAVE_FREEZERO libcompat_la_SOURCES += compat/freezero.c endif -if !HAVE_FTRUNCATE -libcompat_la_SOURCES += compat/ftruncate.c -endif - if !HAVE_GETDELIM libcompat_la_SOURCES += compat/getdelim.c endif diff --git a/crypto/compat/ftruncate.c b/crypto/compat/ftruncate.c deleted file mode 100644 index e825e50..0000000 --- a/crypto/compat/ftruncate.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Public domain - * - * Kinichiro Inoguchi - */ - -#ifdef _WIN32 - -#include - -int -ftruncate(int fd, off_t length) -{ - return _chsize(fd, length); -} - -#endif diff --git a/crypto/compat/posix_win.c b/crypto/compat/posix_win.c index 4e98643..60b2896 100644 --- a/crypto/compat/posix_win.c +++ b/crypto/compat/posix_win.c @@ -68,6 +68,14 @@ libressl_fstat(int fd, struct stat *statbuf) return fstat(get_real_fd(fd), statbuf); } +#ifndef HAVE_FTRUNCATE +int +ftruncate(int fd, off_t length) +{ + return _chsize(get_real_fd(fd), length); +} +#endif + int posix_open(const char *path, ...) { -- cgit v1.2.3-55-g6feb