From: Bruno Haible Date: Sun, 21 May 2023 12:40:04 +0000 (+0200) Subject: ssize_t: Fix replacement on 64-bit Windows. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=2f120db356d42362be4c1ab57f96ffe7ec87f27a;p=gnulib.git ssize_t: Fix replacement on 64-bit Windows. * m4/ssize_t.m4 (gt_TYPE_SSIZE_T): Use prefix 'gl_' instead of 'gt_'. Define ssize_t to 'long long' or 'long', depending on the width of 'size_t'. --- diff --git a/ChangeLog b/ChangeLog index 0e506f60a7..b322e5c6d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-05-21 Bruno Haible + + ssize_t: Fix replacement on 64-bit Windows. + * m4/ssize_t.m4 (gt_TYPE_SSIZE_T): Use prefix 'gl_' instead of 'gt_'. + Define ssize_t to 'long long' or 'long', depending on the width of + 'size_t'. + 2023-05-18 Bruno Haible astrxfrm: Fix use-after-free bug. diff --git a/m4/ssize_t.m4 b/m4/ssize_t.m4 index 1c12c33ea0..52bd77d2ae 100644 --- a/m4/ssize_t.m4 +++ b/m4/ssize_t.m4 @@ -1,23 +1,37 @@ -# ssize_t.m4 serial 5 (gettext-0.18.2) +# ssize_t.m4 serial 6 dnl Copyright (C) 2001-2003, 2006, 2010-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. -dnl Test whether ssize_t is defined. +dnl Define ssize_t if it does not already exist. AC_DEFUN([gt_TYPE_SSIZE_T], [ - AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t], + AC_CACHE_CHECK([for ssize_t], [gl_cv_ssize_t], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[#include ]], [[int x = sizeof (ssize_t *) + sizeof (ssize_t); return !x;]])], - [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])]) - if test $gt_cv_ssize_t = no; then - AC_DEFINE([ssize_t], [int], - [Define as a signed type of the same size as size_t.]) + [gl_cv_ssize_t=yes], [gl_cv_ssize_t=no])]) + if test $gl_cv_ssize_t = no; then + dnl On 64-bit native Windows, ssize_t needs to be defined as 'long long', + dnl for consistency with the 64-bit size_t. + AC_CACHE_CHECK([whether size_t is wider than 'long'], [gl_cv_size_t_large], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + typedef int array [2 * (sizeof (size_t) > sizeof (long)) - 1]; + ]])], + [gl_cv_size_t_large=yes], [gl_cv_size_t_large=no])]) + if test $gl_cv_size_t_large = yes; then + gl_def_ssize_t='long long' + else + gl_def_ssize_t='long' + fi + AC_DEFINE_UNQUOTED([ssize_t], [$gl_def_ssize_t], + [Define as a signed type of the same size as size_t.]) fi ])