]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
man/: Use countof() instead of _Countof()
authorAlejandro Colomar <alx@kernel.org>
Tue, 10 Feb 2026 20:53:41 +0000 (21:53 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 10 Feb 2026 20:54:16 +0000 (21:54 +0100)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
man/man2/bpf.2
man/man2/seccomp.2
man/man2/seccomp_unotify.2
man/man2/sysctl.2
man/man3/bsearch.3
man/man3/fread.3
man/man3/regex.3
man/man3/strncat.3
man/man7/string_copying.7

index 3d6a9248af9f64bd6f67b03e9f1a840b042eba2c..2b9e9263633a091f6424584d6facbcb1b7231cdb 100644 (file)
@@ -1208,6 +1208,8 @@ riscv
 .SH EXAMPLES
 .\" SRC BEGIN (bpf.c)
 .EX
+#include <stdcountof.h>
+\&
 /* bpf+sockets example:
  * 1.  create array map of 256 elements
  * 2.  load program that counts number of packets received
@@ -1252,7 +1254,7 @@ main(int argc, char *argv[])
     };
 \&
     prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, prog,
-                            _Countof(prog), "GPL");
+                            countof(prog), "GPL");
 \&
     sock = open_raw_sock("lo");
 \&
index 9a0b865be78a75ea2a9d607670c9d4600f57403c..75c7b2d5828c3252de667fbc734390456dbd601b 100644 (file)
@@ -1110,6 +1110,7 @@ cecilia
 #include <linux/audit.h>
 #include <linux/filter.h>
 #include <linux/seccomp.h>
+#include <stdcountof.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1168,7 +1169,7 @@ install_filter(int syscall_nr, unsigned int t_arch, int f_errno)
     };
 \&
     struct sock_fprog prog = {
-        .len = _Countof(filter),
+        .len = countof(filter),
         .filter = filter,
     };
 \&
index 89f5f2cd7b3ad3fb51c6027c2f82cb78502d8e00..1071407c8101eb72ba0edaa9b012390d41480021 100644 (file)
@@ -1415,6 +1415,7 @@ T: terminating
 #include <linux/seccomp.h>
 #include <signal.h>
 #include <stdbool.h>
+#include <stdcountof.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -1608,7 +1609,7 @@ installNotifyFilter(void)
     };
 \&
     struct sock_fprog prog = {
-        .len = _Countof(filter),
+        .len = countof(filter),
         .filter = filter,
     };
 \&
index 76c5b87e2e77b193e56b58e279e222789b656c79..a3add8e5fde981005e7442f27fd582146ccc3994 100644 (file)
@@ -112,6 +112,7 @@ It is not yet possible to change operating system by writing to
 .\" SRC BEGIN (sysctl.c)
 .EX
 #define _GNU_SOURCE
+#include <stdcountof.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -134,7 +135,7 @@ main(void)
 \&
     memset(&args, 0, sizeof(args));
     args.name = name;
-    args.nlen = _Countof(name);
+    args.nlen = countof(name);
     args.oldval = osname;
     args.oldlenp = &osnamelth;
 \&
index 40150f4ac1c1b2546dbc4243d8141d629b8595a3..6581208926c806addb94ed64fc5ef43b8d538414 100644 (file)
@@ -81,6 +81,7 @@ then retrieves desired elements using
 .P
 .\" SRC BEGIN (bsearch.c)
 .EX
+#include <stdcountof.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -108,13 +109,13 @@ compmi(const void *m1, const void *m2)
 int
 main(int argc, char *argv[])
 {
-    qsort(months, _Countof(months), sizeof(months[0]), compmi);
+    qsort(months, countof(months), sizeof(months[0]), compmi);
     for (size_t i = 1; i < argc; i++) {
         struct mi key;
         struct mi *res;
 \&
         key.name = argv[i];
-        res = bsearch(&key, months, _Countof(months),
+        res = bsearch(&key, months, countof(months),
                       sizeof(months[0]), compmi);
         if (res == NULL)
             printf("\[aq]%s\[aq]: unknown month\[rs]n", argv[i]);
index 9ad56580c9c259f63e7660a9f211949974e10a4d..1d6763254f51a8e76f57f8079243da949ed74aea 100644 (file)
@@ -106,6 +106,7 @@ Class: 0x02
 \&
 .\" SRC BEGIN (fread.c)
 .EX
+#include <stdcountof.h>
 #include <stdio.h>
 #include <stdlib.h>
 \&
@@ -122,8 +123,8 @@ main(void)
         return EXIT_FAILURE;
     }
 \&
-    ret = fread(buffer, sizeof(*buffer), _Countof(buffer), fp);
-    if (ret != _Countof(buffer)) {
+    ret = fread(buffer, sizeof(*buffer), countof(buffer), fp);
+    if (ret != countof(buffer)) {
         fprintf(stderr, "fread() failed: %zu\[rs]n", ret);
         exit(EXIT_FAILURE);
     }
index f6dc532f22540c96506a221f610d2878a258c03e..4b8376faea10d95a234c327535af5029ceb4a718 100644 (file)
@@ -358,6 +358,7 @@ Always reference them by name.
 .\" illumos has two more start/end pairs and the first one is of pointers
 .SH EXAMPLES
 .EX
+#include <stdcountof.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -381,7 +382,7 @@ int main(void)
     printf("Matches:\[rs]n");
 \&
     for (unsigned int i = 0; ; i++) {
-        if (regexec(&regex, s, _Countof(pmatch), pmatch, 0))
+        if (regexec(&regex, s, countof(pmatch), pmatch, 0))
             break;
 \&
         off = pmatch[0].rm_so + (s \- str);
index 4066ae4b17d3c82d00eae01d39786b60acdad453..bc07756763191c91f01166f80e2d09b8f887c659 100644 (file)
@@ -90,6 +90,7 @@ Shlemiel the painter
 .SH EXAMPLES
 .\" SRC BEGIN (strncat.c)
 .EX
+#include <stdcountof.h>
 #include <stdio.h>
 #include <string.h>
 #include <utmp.h>
@@ -99,10 +100,10 @@ void print_ut_user(struct utmp *ut);
 void
 print_ut_user(struct utmp *ut)
 {
-       char  buf[_Countof(ut\->ut_user) + 1];
+       char  buf[countof(ut\->ut_user) + 1];
 \&
        strcpy(buf, "");
-       strncat(buf, ut\->ut_user, _Countof(ut\->ut_user));
+       strncat(buf, ut\->ut_user, countof(ut\->ut_user));
        puts(buf);
 }
 .EE
index 1a0e760a8a34e7b1a3b419888c0820328536ae59..05d8536a6049f7eb08645eeaebb2617daae15348 100644 (file)
@@ -53,10 +53,10 @@ strncat
 .BI "               size_t " dsize );
 .P
 // Chain-copy a null-padded character sequence into a character sequence.
-.I mempcpy(dst, src, strnlen(src, _Countof(src)));
+.I mempcpy(dst, src, strnlen(src, countof(src)));
 .P
 // Chain-copy a null-padded character sequence into a string.
-.I stpcpy(mempcpy(dst, src, strnlen(src, _Countof(src))), \[dq]\[dq]);
+.I stpcpy(mempcpy(dst, src, strnlen(src, countof(src))), \[dq]\[dq]);
 .P
 // Catenate a null-padded character sequence into a string.
 .BR "char *strncat(" "size_t ssize;"
@@ -259,7 +259,7 @@ or
 .P
 To read a null-padded character sequence,
 use
-.IR "strnlen(src,\ _Countof(src))" ,
+.IR "strnlen(src,\ countof(src))" ,
 and then you can treat it as a length-bounded character sequence;
 or use
 .BR strncat (3)
@@ -468,7 +468,7 @@ Do not confuse this function with
 .BR strncpy (3);
 they are not related at all.
 .IP
-.I \%stpcpy(mempcpy(dst,\ src,\ strnlen(src,\ _Countof(src))),\ \[dq]\[dq])
+.I \%stpcpy(mempcpy(dst,\ src,\ strnlen(src,\ countof(src))),\ \[dq]\[dq])
 is a faster alternative to this function.
 .\" ----- DESCRIPTION :: Functions :: strndup(3) ----------------------/
 .TP
@@ -638,13 +638,13 @@ puts(buf);
 .TP
 .BR stpecpy ()
 .EX
-end = buf + _Countof(buf);
+end = buf + countof(buf);
 p = buf;
 p = stpecpy(p, end, "Hello ");
 p = stpecpy(p, end, "world");
 p = stpecpy(p, end, "!");
 if (p == NULL) {
-    len = _Countof(buf) \- 1;
+    len = countof(buf) \- 1;
     goto toolong;
 }
 len = p \- buf;
@@ -654,7 +654,7 @@ puts(buf);
 .TP
 .BR strtcpy ()
 .EX
-len = strtcpy(buf, "Hello world!", _Countof(buf));
+len = strtcpy(buf, "Hello world!", countof(buf));
 if (len == \-1)
     goto toolong;
 puts(buf);
@@ -665,12 +665,12 @@ puts(buf);
 .TQ
 .BR strlcat (3bsd)
 .EX
-if (strlcpy(buf, "Hello ", _Countof(buf)) >= _Countof(buf))
+if (strlcpy(buf, "Hello ", countof(buf)) >= countof(buf))
     goto toolong;
-if (strlcat(buf, "world", _Countof(buf)) >= _Countof(buf))
+if (strlcat(buf, "world", countof(buf)) >= countof(buf))
     goto toolong;
-len = strlcat(buf, "!", _Countof(buf));
-if (len >= _Countof(buf))
+len = strlcat(buf, "!", countof(buf));
+if (len >= countof(buf))
     goto toolong;
 puts(buf);
 .EE
@@ -678,8 +678,8 @@ puts(buf);
 .TP
 .BR stpncpy (3)
 .EX
-p = stpncpy(u->ut_user, "alx", _Countof(u->ut_user));
-if (_Countof(u->ut_user) < strlen("alx"))
+p = stpncpy(u->ut_user, "alx", countof(u->ut_user));
+if (countof(u->ut_user) < strlen("alx"))
     goto toolong;
 len = p \- u->ut_user;
 fwrite(u->ut_user, 1, len, stdout);
@@ -688,29 +688,29 @@ fwrite(u->ut_user, 1, len, stdout);
 .TP
 .BR strncpy (3)
 .EX
-strncpy(u->ut_user, "alx", _Countof(u->ut_user));
-if (_Countof(u->ut_user) < strlen("alx"))
+strncpy(u->ut_user, "alx", countof(u->ut_user));
+if (countof(u->ut_user) < strlen("alx"))
     goto toolong;
-len = strnlen(u->ut_user, _Countof(u->ut_user));
+len = strnlen(u->ut_user, countof(u->ut_user));
 fwrite(u->ut_user, 1, len, stdout);
 .EE
-.\" ----- EXAMPLES :: mempcpy(dst, src, strnlen(src, _Countof(src))) ----/
+.\" ----- EXAMPLES :: mempcpy(dst, src, strnlen(src, countof(src))) ----/
 .TP
-.I mempcpy(dst, src, strnlen(src, _Countof(src)))
+.I mempcpy(dst, src, strnlen(src, countof(src)))
 .EX
-char  buf[_Countof(u->ut_user)];
+char  buf[countof(u->ut_user)];
 p = buf;
-p = mempcpy(p, u->ut_user, strnlen(u->ut_user, _Countof(u->ut_user)));
+p = mempcpy(p, u->ut_user, strnlen(u->ut_user, countof(u->ut_user)));
 len = p \- buf;
 fwrite(buf, 1, len, stdout);
 .EE
-.\" ----- EXAMPLES :: stpcpy(mempcpy(dst, src, strnlen(src, _Countof(src))), "")
+.\" ----- EXAMPLES :: stpcpy(mempcpy(dst, src, strnlen(src, countof(src))), "")
 .TP
-.I stpcpy(mempcpy(dst, src, strnlen(src, _Countof(src))), \[dq]\[dq])
+.I stpcpy(mempcpy(dst, src, strnlen(src, countof(src))), \[dq]\[dq])
 .EX
-char  buf[_Countof(u->ut_user) + 1];
+char  buf[countof(u->ut_user) + 1];
 p = buf;
-p = mempcpy(p, u->ut_user, strnlen(u->ut_user, _Countof(u->ut_user)));
+p = mempcpy(p, u->ut_user, strnlen(u->ut_user, countof(u->ut_user)));
 p = stpcpy(p, "");
 len = p \- buf;
 puts(buf);
@@ -719,9 +719,9 @@ puts(buf);
 .TP
 .BR strncat (3)
 .EX
-char  buf[_Countof(u->ut_user) + 1];
+char  buf[countof(u->ut_user) + 1];
 strcpy(buf, "");
-strncat(buf, u->ut_user, _Countof(u->ut_user));
+strncat(buf, u->ut_user, countof(u->ut_user));
 len = strlen(buf);
 puts(buf);
 .EE
@@ -729,7 +729,7 @@ puts(buf);
 .TP
 .BR strndup (3)
 .EX
-buf = strndup(u->ut_user, _Countof(u->ut_user));
+buf = strndup(u->ut_user, countof(u->ut_user));
 len = strlen(buf);
 puts(buf);
 free(buf);