From b2927d1b1fa3fb09a2210a3df5691f7d48d6151b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 16 Feb 2025 12:21:53 +0100 Subject: [PATCH] strcasecmp, strncasecmp: New modules. * modules/strcasecmp: New file. * modules/strncasecmp: New file. * modules/strcase: Merely depend on strcasecmp, strncasecmp. * m4/strcasecmp.m4: New file, based on m4/strcase.m4. * m4/strncasecmp.m4: New file, based on m4/strcase.m4. * m4/strcase.m4: Remove file. * lib/strings.in.h (strcasecmp, strncasecmp): Fix typo in warning message. * lib/strcasecmp.c: Improve comment. * lib/strncasecmp.c: Likewise. * doc/posix-functions/strcasecmp.texi: Mention module strcasecmp, not module strcase. * doc/posix-functions/strncasecmp.texi: Mention module strncasecmp, not module strcase. * doc/strings.texi (Comparison of string APIs): Reference modules strcasecmp, strncasecmp. * modules/argp (Depends-on): Add strcasecmp. Remove strcase. * modules/strcasestr-simple (Depends-on): Add strncasecmp. Remove strcase. * modules/strptime (Depends-on): Likewise. --- ChangeLog | 24 ++++++++++++++++++++++ doc/posix-functions/strcasecmp.texi | 4 ++-- doc/posix-functions/strncasecmp.texi | 4 ++-- doc/strings.texi | 3 ++- lib/strcasecmp.c | 2 +- lib/strings.in.h | 8 ++++---- lib/strncasecmp.c | 2 +- m4/strcasecmp.m4 | 21 +++++++++++++++++++ m4/{strcase.m4 => strncasecmp.m4} | 26 +++--------------------- modules/argp | 2 +- modules/strcase | 23 +++------------------ modules/strcasecmp | 30 ++++++++++++++++++++++++++++ modules/strcasestr-simple | 2 +- modules/strncasecmp | 30 ++++++++++++++++++++++++++++ modules/strptime | 2 +- 15 files changed, 126 insertions(+), 57 deletions(-) create mode 100644 m4/strcasecmp.m4 rename m4/{strcase.m4 => strncasecmp.m4} (61%) create mode 100644 modules/strcasecmp create mode 100644 modules/strncasecmp diff --git a/ChangeLog b/ChangeLog index 53bb437073..37255b17ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2025-02-16 Bruno Haible + + strcasecmp, strncasecmp: New modules. + * modules/strcasecmp: New file. + * modules/strncasecmp: New file. + * modules/strcase: Merely depend on strcasecmp, strncasecmp. + * m4/strcasecmp.m4: New file, based on m4/strcase.m4. + * m4/strncasecmp.m4: New file, based on m4/strcase.m4. + * m4/strcase.m4: Remove file. + * lib/strings.in.h (strcasecmp, strncasecmp): Fix typo in warning + message. + * lib/strcasecmp.c: Improve comment. + * lib/strncasecmp.c: Likewise. + * doc/posix-functions/strcasecmp.texi: Mention module strcasecmp, not + module strcase. + * doc/posix-functions/strncasecmp.texi: Mention module strncasecmp, not + module strcase. + * doc/strings.texi (Comparison of string APIs): Reference modules + strcasecmp, strncasecmp. + * modules/argp (Depends-on): Add strcasecmp. Remove strcase. + * modules/strcasestr-simple (Depends-on): Add strncasecmp. Remove + strcase. + * modules/strptime (Depends-on): Likewise. + 2025-02-16 Bruno Haible ctype-h: Make ctype.h self-contained again (regr. 2025-02-14). diff --git a/doc/posix-functions/strcasecmp.texi b/doc/posix-functions/strcasecmp.texi index 2de26616b2..af640589d9 100644 --- a/doc/posix-functions/strcasecmp.texi +++ b/doc/posix-functions/strcasecmp.texi @@ -4,8 +4,8 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html} -Gnulib module: strcase -@mindex strcase +Gnulib module: strcasecmp +@mindex strcasecmp Portability problems fixed by Gnulib: @itemize diff --git a/doc/posix-functions/strncasecmp.texi b/doc/posix-functions/strncasecmp.texi index 5273870215..1fc9e0307a 100644 --- a/doc/posix-functions/strncasecmp.texi +++ b/doc/posix-functions/strncasecmp.texi @@ -4,8 +4,8 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncasecmp.html} -Gnulib module: strcase -@mindex strcase +Gnulib module: strncasecmp +@mindex strncasecmp Portability problems fixed by Gnulib: @itemize diff --git a/doc/strings.texi b/doc/strings.texi index 0493233ba0..a33067f1f8 100644 --- a/doc/strings.texi +++ b/doc/strings.texi @@ -324,11 +324,12 @@ and in Gnulib. @mindex mbs_startswith @mindex stpcpy @mindex stpncpy -@mindex strcase +@mindex strcasecmp @mindex strcasestr @mindex strcspn @mindex strdup @mindex string-desc +@mindex strncasecmp @mindex strncat @mindex strndup @mindex strnlen diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c index 27329368ad..fe21a6d5b3 100644 --- a/lib/strcasecmp.c +++ b/lib/strcasecmp.c @@ -1,4 +1,4 @@ -/* Case-insensitive string comparison function. +/* Case-insensitive string comparison function for unibyte locales. Copyright (C) 1998-1999, 2005-2007, 2009-2025 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify diff --git a/lib/strings.in.h b/lib/strings.in.h index b09f3eed89..f99b7c95e8 100644 --- a/lib/strings.in.h +++ b/lib/strings.in.h @@ -89,8 +89,8 @@ extern int strcasecmp (char const *s1, char const *s2) _GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character " "strings in multibyte locales - " "use mbscasecmp if you care about " - "internationalization, or use c_strcasecmp , " - "gnulib module c-strcase) if you want a locale " + "internationalization, or use c_strcasecmp " + "(gnulib module c-strcase) if you want a locale " "independent function"); # endif #endif @@ -112,8 +112,8 @@ extern int strncasecmp (char const *s1, char const *s2, size_t n) _GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character " "strings in multibyte locales - " "use mbsncasecmp or mbspcasecmp if you care about " - "internationalization, or use c_strncasecmp , " - "gnulib module c-strcase) if you want a locale " + "internationalization, or use c_strncasecmp " + "(gnulib module c-strcase) if you want a locale " "independent function"); # endif #endif diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c index 815843859a..7a0115d050 100644 --- a/lib/strncasecmp.c +++ b/lib/strncasecmp.c @@ -1,4 +1,4 @@ -/* strncasecmp.c -- case insensitive string comparator +/* Case-insensitive string comparison function for unibyte locales. Copyright (C) 1998-1999, 2005-2007, 2009-2025 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify diff --git a/m4/strcasecmp.m4 b/m4/strcasecmp.m4 new file mode 100644 index 0000000000..0bbcc5ebe2 --- /dev/null +++ b/m4/strcasecmp.m4 @@ -0,0 +1,21 @@ +# strcasecmp.m4 +# serial 1 +dnl Copyright (C) 2002-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_STRCASECMP], +[ + AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) + AC_CHECK_FUNCS([strcasecmp]) + if test $ac_cv_func_strcasecmp = no; then + HAVE_STRCASECMP=0 + fi +]) + +# Prerequisites of lib/strcasecmp.c. +AC_DEFUN([gl_PREREQ_STRCASECMP], [ + : +]) diff --git a/m4/strcase.m4 b/m4/strncasecmp.m4 similarity index 61% rename from m4/strcase.m4 rename to m4/strncasecmp.m4 index ecb2c91c8b..d27a4a0c5e 100644 --- a/m4/strcase.m4 +++ b/m4/strncasecmp.m4 @@ -1,26 +1,11 @@ -# strcase.m4 -# serial 12 -dnl Copyright (C) 2002, 2005-2025 Free Software Foundation, Inc. +# strncasecmp.m4 +# serial 1 +dnl Copyright (C) 2002-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_STRCASE], -[ - gl_FUNC_STRCASECMP - gl_FUNC_STRNCASECMP -]) - -AC_DEFUN([gl_FUNC_STRCASECMP], -[ - AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) - AC_CHECK_FUNCS([strcasecmp]) - if test $ac_cv_func_strcasecmp = no; then - HAVE_STRCASECMP=0 - fi -]) - AC_DEFUN([gl_FUNC_STRNCASECMP], [ AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) @@ -36,11 +21,6 @@ AC_DEFUN([gl_FUNC_STRNCASECMP], fi ]) -# Prerequisites of lib/strcasecmp.c. -AC_DEFUN([gl_PREREQ_STRCASECMP], [ - : -]) - # Prerequisites of lib/strncasecmp.c. AC_DEFUN([gl_PREREQ_STRNCASECMP], [ : diff --git a/modules/argp b/modules/argp index 8b4e3e297b..caff9430cb 100644 --- a/modules/argp +++ b/modules/argp @@ -28,7 +28,7 @@ sysexits-h malloc-gnu mempcpy strndup -strcase +strcasecmp extensions vsnprintf sleep diff --git a/modules/strcase b/modules/strcase index 4d90a042a5..91bdd02d39 100644 --- a/modules/strcase +++ b/modules/strcase @@ -1,32 +1,15 @@ Description: -Case-insensitive string comparison functions. +Case-insensitive string comparison functions for unibyte locales. Files: -lib/strcasecmp.c -lib/strncasecmp.c -m4/strcase.m4 Depends-on: -strings-h +strcasecmp +strncasecmp configure.ac: -gl_STRCASE -gl_CONDITIONAL([GL_COND_OBJ_STRCASECMP], [test $HAVE_STRCASECMP = 0]) -AM_COND_IF([GL_COND_OBJ_STRCASECMP], [ - gl_PREREQ_STRCASECMP -]) -gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP], [test $HAVE_STRNCASECMP = 0]) -AM_COND_IF([GL_COND_OBJ_STRNCASECMP], [ - gl_PREREQ_STRNCASECMP -]) Makefile.am: -if GL_COND_OBJ_STRCASECMP -lib_SOURCES += strcasecmp.c -endif -if GL_COND_OBJ_STRNCASECMP -lib_SOURCES += strncasecmp.c -endif Include: diff --git a/modules/strcasecmp b/modules/strcasecmp new file mode 100644 index 0000000000..b226990b2a --- /dev/null +++ b/modules/strcasecmp @@ -0,0 +1,30 @@ +Description: +Case-insensitive string comparison function for unibyte locales. + +Files: +lib/strcasecmp.c +m4/strcasecmp.m4 + +Depends-on: +strings-h + +configure.ac: +gl_FUNC_STRCASECMP +gl_CONDITIONAL([GL_COND_OBJ_STRCASECMP], [test $HAVE_STRCASECMP = 0]) +AM_COND_IF([GL_COND_OBJ_STRCASECMP], [ + gl_PREREQ_STRCASECMP +]) + +Makefile.am: +if GL_COND_OBJ_STRCASECMP +lib_SOURCES += strcasecmp.c +endif + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/strcasestr-simple b/modules/strcasestr-simple index 050bd81903..f944425ff0 100644 --- a/modules/strcasestr-simple +++ b/modules/strcasestr-simple @@ -9,7 +9,7 @@ m4/strcasestr.m4 Depends-on: string-h bool -strcase +strncasecmp memchr memcmp extensions diff --git a/modules/strncasecmp b/modules/strncasecmp new file mode 100644 index 0000000000..5fca265bad --- /dev/null +++ b/modules/strncasecmp @@ -0,0 +1,30 @@ +Description: +Case-insensitive string comparison function for unibyte locales. + +Files: +lib/strncasecmp.c +m4/strncasecmp.m4 + +Depends-on: +strings-h + +configure.ac: +gl_FUNC_STRNCASECMP +gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP], [test $HAVE_STRNCASECMP = 0]) +AM_COND_IF([GL_COND_OBJ_STRNCASECMP], [ + gl_PREREQ_STRNCASECMP +]) + +Makefile.am: +if GL_COND_OBJ_STRNCASECMP +lib_SOURCES += strncasecmp.c +endif + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/strptime b/modules/strptime index 9ebb97e2fe..67296f76c8 100644 --- a/modules/strptime +++ b/modules/strptime @@ -11,7 +11,7 @@ time-h extensions sys_time-h [test $HAVE_STRPTIME = 0] string-h [test $HAVE_STRPTIME = 0] -strcase [test $HAVE_STRPTIME = 0] +strncasecmp [test $HAVE_STRPTIME = 0] bool [test $HAVE_STRPTIME = 0] time_r [test $HAVE_STRPTIME = 0] -- 2.39.5