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 ++++++++ m4/check-libc.m4 | 1 - 5 files changed, 8 insertions(+), 26 deletions(-) delete mode 100644 crypto/compat/ftruncate.c 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, ...) { diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 42867cc..8ecc89a 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 @@ -39,7 +39,6 @@ AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ ]) AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) -AM_CONDITIONAL([HAVE_FTRUNCATE], [test "x$ac_cv_func_ftruncate" = xyes]) AM_CONDITIONAL([HAVE_GETDELIM], [test "x$ac_cv_func_getdelim" = xyes]) AM_CONDITIONAL([HAVE_GETLINE], [test "x$ac_cv_func_getline" = xyes]) AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) -- cgit v1.2.3-55-g6feb