From: Bruno Haible Date: Sun, 16 Feb 2025 05:55:52 +0000 (+0100) Subject: toupper_l: New module. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f8280181a4a09480febe7120b69116f2359dd4d;p=thirdparty%2Fgnulib.git toupper_l: New module. * lib/ctype.in.h: (toupper_l): New declaration. * lib/toupper_l.c: New file. * m4/toupper_l.m4: New file. * m4/ctype_h.m4 (gl_CTYPE_H): Test for toupper_l. (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOUPPER_L. (gl_CTYPE_H_DEFAULTS): Initialize HAVE_TOUPPER_L. * modules/ctype-h (Makefile.am): Substitute GNULIB_TOUPPER_L, HAVE_TOUPPER_L. * modules/toupper_l: New file. * tests/test-ctype-h-c++.cc: Check declaration of toupper_l. * doc/posix-functions/toupper_l.texi: Mention the new module. --- diff --git a/ChangeLog b/ChangeLog index 8452a7a2d2..6a46a18615 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2025-02-16 Bruno Haible + + toupper_l: New module. + * lib/ctype.in.h: (toupper_l): New declaration. + * lib/toupper_l.c: New file. + * m4/toupper_l.m4: New file. + * m4/ctype_h.m4 (gl_CTYPE_H): Test for toupper_l. + (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOUPPER_L. + (gl_CTYPE_H_DEFAULTS): Initialize HAVE_TOUPPER_L. + * modules/ctype-h (Makefile.am): Substitute GNULIB_TOUPPER_L, + HAVE_TOUPPER_L. + * modules/toupper_l: New file. + * tests/test-ctype-h-c++.cc: Check declaration of toupper_l. + * doc/posix-functions/toupper_l.texi: Mention the new module. + 2025-02-16 Bruno Haible tolower_l: Add tests. diff --git a/doc/posix-functions/toupper_l.texi b/doc/posix-functions/toupper_l.texi index 19c76c2a10..e4540df328 100644 --- a/doc/posix-functions/toupper_l.texi +++ b/doc/posix-functions/toupper_l.texi @@ -4,15 +4,16 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper_l.html} -Gnulib module: --- +Gnulib module: toupper_l +@mindex toupper_l Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +FreeBSD 9.0, NetBSD 6.1, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, Solaris 11.3, Cygwin 2.5.x, mingw, MSVC 14, Android 4.4. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -FreeBSD 6.0, NetBSD 5.0, OpenBSD 6.0, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.3, Cygwin 1.7.x, mingw, MSVC 14, Android 4.4. @end itemize diff --git a/lib/ctype.in.h b/lib/ctype.in.h index e5259709f0..130ef7e0d3 100644 --- a/lib/ctype.in.h +++ b/lib/ctype.in.h @@ -58,7 +58,7 @@ || @GNULIB_ISCNTRL_L@ || @GNULIB_ISDIGIT_L@ || @GNULIB_ISGRAPH_L@ \ || @GNULIB_ISLOWER_L@ || @GNULIB_ISPRINT_L@ || @GNULIB_ISPUNCT_L@ \ || @GNULIB_ISSPACE_L@ || @GNULIB_ISUPPER_L@ || @GNULIB_ISXDIGIT_L@ \ - || @GNULIB_TOLOWER_L@) + || @GNULIB_TOLOWER_L@ || @GNULIB_TOUPPER_L@) /* Get locale_t. */ # include #endif @@ -314,6 +314,24 @@ _GL_WARN_ON_USE (tolower_l, "tolower_l is unportable - " # endif #endif +/* Map c to uppercase. */ +#if @GNULIB_TOUPPER_L@ +# if !@HAVE_TOUPPER_L@ +_GL_FUNCDECL_SYS (toupper_l, int, (int c, locale_t locale), + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (toupper_l, int, (int c, locale_t locale)); +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (toupper_l); +# endif +#elif defined GNULIB_POSIXCHECK +# undef toupper_l +# if HAVE_RAW_DECL_TOUPPER_L +_GL_WARN_ON_USE (toupper_l, "toupper_l is unportable - " + "use gnulib module toupper_l for portability"); +# endif +#endif + #endif /* _@GUARD_PREFIX@_CTYPE_H */ #endif #endif /* _@GUARD_PREFIX@_CTYPE_H */ diff --git a/lib/toupper_l.c b/lib/toupper_l.c new file mode 100644 index 0000000000..329c3950eb --- /dev/null +++ b/lib/toupper_l.c @@ -0,0 +1,31 @@ +/* Mapping a single-byte character to uppercase. + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2025. */ + +#include + +/* Specification. */ +#include + +#define FUNC toupper_l +#define GLOBAL_FUNC toupper +#define C_FUNC(c) \ + (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c) +/* Documentation: + */ +#define WINDOWS_FUNC _toupper_l +#include "to_l-impl.h" diff --git a/m4/ctype_h.m4 b/m4/ctype_h.m4 index fa459e2b62..fec7c458bb 100644 --- a/m4/ctype_h.m4 +++ b/m4/ctype_h.m4 @@ -1,5 +1,5 @@ # ctype_h.m4 -# serial 22 +# serial 23 dnl Copyright (C) 2009-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -18,7 +18,7 @@ AC_DEFUN_ONCE([gl_CTYPE_H], gl_WARN_ON_USE_PREPARE([[#include ]], [isalnum_l isalpha_l isblank isblank_l iscntrl_l isdigit_l isgraph_l islower_l isprint_l ispunct_l isspace_l isupper_l isxdigit_l - tolower_l]) + tolower_l toupper_l]) ]) # gl_CTYPE_MODULE_INDICATOR([modulename]) @@ -52,6 +52,7 @@ AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISUPPER_L]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISXDIGIT_L]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOLOWER_L]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOUPPER_L]) ]) m4_require(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS]) AC_REQUIRE([gl_CTYPE_H_DEFAULTS]) @@ -74,4 +75,5 @@ AC_DEFUN([gl_CTYPE_H_DEFAULTS], HAVE_ISUPPER_L=1; AC_SUBST([HAVE_ISUPPER_L]) HAVE_ISXDIGIT_L=1; AC_SUBST([HAVE_ISXDIGIT_L]) HAVE_TOLOWER_L=1; AC_SUBST([HAVE_TOLOWER_L]) + HAVE_TOUPPER_L=1; AC_SUBST([HAVE_TOUPPER_L]) ]) diff --git a/m4/toupper_l.m4 b/m4/toupper_l.m4 new file mode 100644 index 0000000000..4283f3a76e --- /dev/null +++ b/m4/toupper_l.m4 @@ -0,0 +1,23 @@ +# toupper_l.m4 +# serial 1 +dnl Copyright (C) 2009-2025 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 This file is offered as-is, without any warranty. + +AC_DEFUN([gl_FUNC_TOUPPER_L], +[ + AC_REQUIRE([gl_CTYPE_H_DEFAULTS]) + + dnl Persuade glibc to declare toupper_l(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS_ONCE([toupper_l]) + if test $ac_cv_func_toupper_l = no; then + HAVE_TOUPPER_L=0 + fi + + dnl Prerequisites of lib/toupper_l.c. + AC_REQUIRE([gt_FUNC_USELOCALE]) +]) diff --git a/modules/ctype-h b/modules/ctype-h index cf36d5e1da..56edc715b6 100644 --- a/modules/ctype-h +++ b/modules/ctype-h @@ -44,6 +44,7 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's/@''GNULIB_ISUPPER_L''@/$(GNULIB_ISUPPER_L)/g' \ -e 's/@''GNULIB_ISXDIGIT_L''@/$(GNULIB_ISXDIGIT_L)/g' \ -e 's/@''GNULIB_TOLOWER_L''@/$(GNULIB_TOLOWER_L)/g' \ + -e 's/@''GNULIB_TOUPPER_L''@/$(GNULIB_TOUPPER_L)/g' \ -e 's/@''HAVE_ISALNUM_L''@/$(HAVE_ISALNUM_L)/g' \ -e 's/@''HAVE_ISALPHA_L''@/$(HAVE_ISALPHA_L)/g' \ -e 's/@''HAVE_ISBLANK''@/$(HAVE_ISBLANK)/g' \ @@ -58,6 +59,7 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's/@''HAVE_ISUPPER_L''@/$(HAVE_ISUPPER_L)/g' \ -e 's/@''HAVE_ISXDIGIT_L''@/$(HAVE_ISXDIGIT_L)/g' \ -e 's/@''HAVE_TOLOWER_L''@/$(HAVE_TOLOWER_L)/g' \ + -e 's/@''HAVE_TOUPPER_L''@/$(HAVE_TOUPPER_L)/g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ $(srcdir)/ctype.in.h > $@-t diff --git a/modules/toupper_l b/modules/toupper_l new file mode 100644 index 0000000000..613da36d24 --- /dev/null +++ b/modules/toupper_l @@ -0,0 +1,33 @@ +Description: +toupper_l() function: map a single-byte character to uppercase. + +Files: +lib/toupper_l.c +lib/to_l-impl.h +m4/toupper_l.m4 +m4/intl-thread-locale.m4 + +Depends-on: +ctype-h +locale-h +extensions + +configure.ac: +gl_FUNC_TOUPPER_L +gl_CONDITIONAL([GL_COND_OBJ_TOUPPER_L], [test $HAVE_TOUPPER_L = 0]) +gl_MODULE_INDICATOR([toupper_l]) +gl_CTYPE_MODULE_INDICATOR([toupper_l]) + +Makefile.am: +if GL_COND_OBJ_TOUPPER_L +lib_SOURCES += toupper_l.c +endif + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/tests/test-ctype-h-c++.cc b/tests/test-ctype-h-c++.cc index 578e99af31..cbf51c415d 100644 --- a/tests/test-ctype-h-c++.cc +++ b/tests/test-ctype-h-c++.cc @@ -80,6 +80,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::isxdigit_l, int, (int, locale_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::tolower_l, int, (int, locale_t)); #endif +#if GNULIB_TEST_TOUPPER_L +SIGNATURE_CHECK (GNULIB_NAMESPACE::toupper_l, int, (int, locale_t)); +#endif + int main ()