Thanks for +1 Bruno, I have pushed the commits below.  More history or
insight on how to think about use of these types would be great.  My
recollection was that these types were preferred for compatibility with
ancient C tools that didn't parse 'unsigned char' etc.

/Simon
From 2adbe3be9e278cfc66289bbd9c8c433db84d5ce4 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <si...@josefsson.org>
Date: Mon, 6 May 2024 14:56:08 +0200
Subject: [PATCH 1/2] inet-ntop, inet-pton: Avoid obsolete u_char type.

* lib/inet_pton.c (inet_pton6): Use unsigned char instead of u_char.
* lib/inet_ntop.c: Doc fix.
---
 ChangeLog       | 6 ++++++
 lib/inet_ntop.c | 2 +-
 lib/inet_pton.c | 8 ++++----
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 02ecbd341d..6b969dddbe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-05-06  Simon Josefsson  <si...@josefsson.org>
+
+	inet-ntop, inet-pton: Avoid obsolete u_char type.
+	* lib/inet_pton.c (inet_pton6): Use unsigned char instead of u_char.
+	* lib/inet_ntop.c: Doc fix.
+
 2024-05-05  Bruno Haible  <br...@clisp.org>
 
 	gnulib-tool.py: Regenerate aclocal.m4 before using 'autoconf -t ...'.
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 0a4ba20e0d..26089959da 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -117,7 +117,7 @@ inet_ntop (int af, const void *restrict src,
  *      'dst' (as a const)
  * notes:
  *      (1) uses no statics
- *      (2) takes a u_char* not an in_addr as input
+ *      (2) takes a 'unsigned char *' not an in_addr as input
  * author:
  *      Paul Vixie, 1996.
  */
diff --git a/lib/inet_pton.c b/lib/inet_pton.c
index 2d29608d47..3d35f37adf 100644
--- a/lib/inet_pton.c
+++ b/lib/inet_pton.c
@@ -217,8 +217,8 @@ inet_pton6 (const char *restrict src, unsigned char *restrict dst)
             }
           if (tp + NS_INT16SZ > endp)
             return (0);
-          *tp++ = (u_char) (val >> 8) & 0xff;
-          *tp++ = (u_char) val & 0xff;
+          *tp++ = (unsigned char) (val >> 8) & 0xff;
+          *tp++ = (unsigned char) val & 0xff;
           saw_xdigit = 0;
           val = 0;
           continue;
@@ -236,8 +236,8 @@ inet_pton6 (const char *restrict src, unsigned char *restrict dst)
     {
       if (tp + NS_INT16SZ > endp)
         return (0);
-      *tp++ = (u_char) (val >> 8) & 0xff;
-      *tp++ = (u_char) val & 0xff;
+      *tp++ = (unsigned char) (val >> 8) & 0xff;
+      *tp++ = (unsigned char) val & 0xff;
     }
   if (colonp != NULL)
     {
-- 
2.34.1

From aacceb6eff58eba91290d930ea9b8275699057cf Mon Sep 17 00:00:00 2001
From: Simon Josefsson <si...@josefsson.org>
Date: Mon, 6 May 2024 15:01:10 +0200
Subject: [PATCH 2/2] maintainer-makefile: Prohibit BSD4.3/SysV u_char etc
 types.

* top/maint.mk (sc_unsigned_char, sc_unsigned_short)
(sc_unsigned_int, sc_unsigned_long): Add.
---
 ChangeLog    |  6 ++++++
 top/maint.mk | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 6b969dddbe..54ac701a98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-05-06  Simon Josefsson  <si...@josefsson.org>
+
+	maintainer-makefile: Prohibit BSD4.3/SysV u_char etc types.
+	* top/maint.mk (sc_unsigned_char, sc_unsigned_short)
+	(sc_unsigned_int, sc_unsigned_long): Add.
+
 2024-05-06  Simon Josefsson  <si...@josefsson.org>
 
 	inet-ntop, inet-pton: Avoid obsolete u_char type.
diff --git a/top/maint.mk b/top/maint.mk
index af865717c4..32228f4366 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -854,6 +854,24 @@ sc_obsolete_symbols:
 	halt='do not use HAVE''_FCNTL_H or O'_NDELAY			\
 	  $(_sc_search_regexp)
 
+# Prohibit BSD4.3/SysV u_char, u_short, u_int and u_long usage.
+sc_unsigned_char:
+	@prohibit=u''_char \
+	halt='don'\''t use u''_char; instead use unsigned char'	\
+	  $(_sc_search_regexp)
+sc_unsigned_short:
+	@prohibit=u''_short \
+	halt='don'\''t use u''_short; instead use unsigned short' \
+	  $(_sc_search_regexp)
+sc_unsigned_int:
+	@prohibit=u''_int \
+	halt='don'\''t use u''_int; instead use unsigned int' \
+	  $(_sc_search_regexp)
+sc_unsigned_long:
+	@prohibit=u''_long \
+	halt='don'\''t use u''_long; instead use unsigned long'	\
+	  $(_sc_search_regexp)
+
 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
 
 # Each nonempty ChangeLog line must start with a year number, or a TAB.
-- 
2.34.1

Attachment: signature.asc
Description: PGP signature

Reply via email to