]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
iscntrl_l: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 15 Feb 2025 09:58:23 +0000 (10:58 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 15 Feb 2025 10:12:42 +0000 (11:12 +0100)
* lib/ctype.in.h: (iscntrl_l): New declaration.
* lib/iscntrl_l.c: New file.
* m4/iscntrl_l.m4: New file.
* m4/ctype_h.m4 (gl_CTYPE_H): Test for iscntrl_l.
(gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISCNTRL_L.
(gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISCNTRL_L.
* modules/ctype-h (Makefile.am): Substitute GNULIB_ISCNTRL_L,
HAVE_ISCNTRL_L.
* modules/iscntrl_l: New file.
* tests/test-ctype-h-c++.cc: Check declaration of iscntrl_l.
* doc/posix-functions/iscntrl_l.texi: Mention the new module.

ChangeLog
doc/posix-functions/iscntrl_l.texi
lib/ctype.in.h
lib/iscntrl_l.c [new file with mode: 0644]
m4/ctype_h.m4
m4/iscntrl_l.m4 [new file with mode: 0644]
modules/ctype-h
modules/iscntrl_l [new file with mode: 0644]
tests/test-ctype-h-c++.cc

index 70d70f7ec36dae1bf6e767669dbe8e8f6fe1a8ae..ddaf810954cd28a753f5b22b5af3dbb44f38ed94 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2025-02-15  Bruno Haible  <bruno@clisp.org>
+
+       iscntrl_l: New module.
+       * lib/ctype.in.h: (iscntrl_l): New declaration.
+       * lib/iscntrl_l.c: New file.
+       * m4/iscntrl_l.m4: New file.
+       * m4/ctype_h.m4 (gl_CTYPE_H): Test for iscntrl_l.
+       (gl_CTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISCNTRL_L.
+       (gl_CTYPE_H_DEFAULTS): Initialize HAVE_ISCNTRL_L.
+       * modules/ctype-h (Makefile.am): Substitute GNULIB_ISCNTRL_L,
+       HAVE_ISCNTRL_L.
+       * modules/iscntrl_l: New file.
+       * tests/test-ctype-h-c++.cc: Check declaration of iscntrl_l.
+       * doc/posix-functions/iscntrl_l.texi: Mention the new module.
+
 2025-02-15  Bruno Haible  <bruno@clisp.org>
 
        isblank_l: Add tests.
index 8eab0d93d7084916ed74a1339971d2d954f9c7e8..0a3d40a01fbb8eb0a2ddc08addbd3705b7248c9f 100644 (file)
@@ -4,15 +4,16 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl_l.html}
 
-Gnulib module: ---
+Gnulib module: iscntrl_l
+@mindex iscntrl_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
index ad52ed0cf24280a56aa589976130b15b8d39f59f..3e14d35a086c44c96848285662b097e9a99a460e 100644 (file)
@@ -54,7 +54,8 @@
  #error "Please include config.h first."
 #endif
 
-#if @GNULIB_ISALNUM_L@ || @GNULIB_ISALPHA_L@ || @GNULIB_ISBLANK_L@
+#if (@GNULIB_ISALNUM_L@ || @GNULIB_ISALPHA_L@ || @GNULIB_ISBLANK_L@ \
+     || @GNULIB_ISCNTRL_L@)
 /* Get locale_t.  */
 # include <locale.h>
 #endif
@@ -130,6 +131,24 @@ _GL_WARN_ON_USE (isblank_l, "isblank_l is unportable - "
 # endif
 #endif
 
+/* Return non-zero if c is a control character.  */
+#if @GNULIB_ISCNTRL_L@
+# if !@HAVE_ISCNTRL_L@
+_GL_FUNCDECL_SYS (iscntrl_l, int, (int c, locale_t locale),
+                                  _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (iscntrl_l, int, (int c, locale_t locale));
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (iscntrl_l);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef iscntrl_l
+# if HAVE_RAW_DECL_ISCNTRL_L
+_GL_WARN_ON_USE (iscntrl_l, "iscntrl_l is unportable - "
+                 "use gnulib module iscntrl_l for portability");
+# endif
+#endif
+
 #endif /* _@GUARD_PREFIX@_CTYPE_H */
 #endif
 #endif /* _@GUARD_PREFIX@_CTYPE_H */
diff --git a/lib/iscntrl_l.c b/lib/iscntrl_l.c
new file mode 100644 (file)
index 0000000..73da7dc
--- /dev/null
@@ -0,0 +1,31 @@
+/* Test whether a single-byte character is a control character.
+   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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <ctype.h>
+
+#define FUNC iscntrl_l
+#define GLOBAL_FUNC iscntrl
+#define C_FUNC(c) \
+  ((c >= 0x00 && c <= 0x1f) || c == 0x7f)
+/* Documentation:
+   <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/iscntrl-iswcntrl-iscntrl-l-iswcntrl-l>  */
+#define WINDOWS_FUNC _iscntrl_l
+#include "is_l-impl.h"
index 926fce3212b07996b717529d105aee46399764d9..10053e3e433dead3bb070deee6beb4a8367be01e 100644 (file)
@@ -1,5 +1,5 @@
 # ctype_h.m4
-# serial 12
+# serial 13
 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,
@@ -16,7 +16,7 @@ AC_DEFUN_ONCE([gl_CTYPE_H],
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <ctype.h>
-    ]], [isalnum_l isalpha_l isblank isblank_l])
+    ]], [isalnum_l isalpha_l isblank isblank_l iscntrl_l])
 ])
 
 # gl_CTYPE_MODULE_INDICATOR([modulename])
@@ -40,6 +40,7 @@ AC_DEFUN([gl_CTYPE_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISALPHA_L])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISBLANK])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISBLANK_L])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISCNTRL_L])
   ])
   m4_require(GL_MODULE_INDICATOR_PREFIX[_CTYPE_H_MODULE_INDICATOR_DEFAULTS])
   AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
@@ -52,4 +53,5 @@ AC_DEFUN([gl_CTYPE_H_DEFAULTS],
   HAVE_ISALPHA_L=1;   AC_SUBST([HAVE_ISALPHA_L])
   HAVE_ISBLANK=1;     AC_SUBST([HAVE_ISBLANK])
   HAVE_ISBLANK_L=1;   AC_SUBST([HAVE_ISBLANK_L])
+  HAVE_ISCNTRL_L=1;   AC_SUBST([HAVE_ISCNTRL_L])
 ])
diff --git a/m4/iscntrl_l.m4 b/m4/iscntrl_l.m4
new file mode 100644 (file)
index 0000000..1202618
--- /dev/null
@@ -0,0 +1,23 @@
+# iscntrl_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_ISCNTRL_L],
+[
+  AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
+
+  dnl Persuade glibc <ctype.h> to declare iscntrl_l().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([iscntrl_l])
+  if test $ac_cv_func_iscntrl_l = no; then
+    HAVE_ISCNTRL_L=0
+  fi
+
+  dnl Prerequisites of lib/iscntrl_l.c.
+  AC_REQUIRE([gt_FUNC_USELOCALE])
+])
index f3c5131acd03bb0108ff5b85f32987e2fb455770..7334f37776fadf84b918bf5fd0b99e8c50b523b9 100644 (file)
@@ -34,10 +34,12 @@ ctype.h: ctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
              -e 's/@''GNULIB_ISALPHA_L''@/$(GNULIB_ISALPHA_L)/g' \
              -e 's/@''GNULIB_ISBLANK''@/$(GNULIB_ISBLANK)/g' \
              -e 's/@''GNULIB_ISBLANK_L''@/$(GNULIB_ISBLANK_L)/g' \
+             -e 's/@''GNULIB_ISCNTRL_L''@/$(GNULIB_ISCNTRL_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' \
              -e 's/@''HAVE_ISBLANK_L''@/$(HAVE_ISBLANK_L)/g' \
+             -e 's/@''HAVE_ISCNTRL_L''@/$(HAVE_ISCNTRL_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/iscntrl_l b/modules/iscntrl_l
new file mode 100644 (file)
index 0000000..30dc266
--- /dev/null
@@ -0,0 +1,33 @@
+Description:
+iscntrl_l() function: test whether a single-byte character is a control character.
+
+Files:
+lib/iscntrl_l.c
+lib/is_l-impl.h
+m4/iscntrl_l.m4
+m4/intl-thread-locale.m4
+
+Depends-on:
+ctype-h
+locale-h
+extensions
+
+configure.ac:
+gl_FUNC_ISCNTRL_L
+gl_CONDITIONAL([GL_COND_OBJ_ISCNTRL_L], [test $HAVE_ISCNTRL_L = 0])
+gl_MODULE_INDICATOR([iscntrl_l])
+gl_CTYPE_MODULE_INDICATOR([iscntrl_l])
+
+Makefile.am:
+if GL_COND_OBJ_ISCNTRL_L
+lib_SOURCES += iscntrl_l.c
+endif
+
+Include:
+<ctype.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index 0f463e3de60a9d84b745421838f50c9783571c69..7031d4458a1d512553f08dc316a5d0acd29649fd 100644 (file)
@@ -40,6 +40,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::isblank, int, (int));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::isblank_l, int, (int, locale_t));
 #endif
 
+#if GNULIB_TEST_ISCNTRL_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::iscntrl_l, int, (int, locale_t));
+#endif
+
 
 int
 main ()