From: Alejandro Colomar Date: Tue, 10 Feb 2026 20:53:41 +0000 (+0100) Subject: man/: Use countof() instead of _Countof() X-Git-Tag: man-pages-6.17~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16ede2dc3ce10fa4a0264873247db1ce6429df6a;p=thirdparty%2Fman-pages.git man/: Use countof() instead of _Countof() Signed-off-by: Alejandro Colomar --- diff --git a/man/man2/bpf.2 b/man/man2/bpf.2 index 3d6a9248a..2b9e92636 100644 --- a/man/man2/bpf.2 +++ b/man/man2/bpf.2 @@ -1208,6 +1208,8 @@ riscv .SH EXAMPLES .\" SRC BEGIN (bpf.c) .EX +#include +\& /* 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"); \& diff --git a/man/man2/seccomp.2 b/man/man2/seccomp.2 index 9a0b865be..75c7b2d58 100644 --- a/man/man2/seccomp.2 +++ b/man/man2/seccomp.2 @@ -1110,6 +1110,7 @@ cecilia #include #include #include +#include #include #include #include @@ -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, }; \& diff --git a/man/man2/seccomp_unotify.2 b/man/man2/seccomp_unotify.2 index 89f5f2cd7..1071407c8 100644 --- a/man/man2/seccomp_unotify.2 +++ b/man/man2/seccomp_unotify.2 @@ -1415,6 +1415,7 @@ T: terminating #include #include #include +#include #include #include #include @@ -1608,7 +1609,7 @@ installNotifyFilter(void) }; \& struct sock_fprog prog = { - .len = _Countof(filter), + .len = countof(filter), .filter = filter, }; \& diff --git a/man/man2/sysctl.2 b/man/man2/sysctl.2 index 76c5b87e2..a3add8e5f 100644 --- a/man/man2/sysctl.2 +++ b/man/man2/sysctl.2 @@ -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 #include #include #include @@ -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; \& diff --git a/man/man3/bsearch.3 b/man/man3/bsearch.3 index 40150f4ac..658120892 100644 --- a/man/man3/bsearch.3 +++ b/man/man3/bsearch.3 @@ -81,6 +81,7 @@ then retrieves desired elements using .P .\" SRC BEGIN (bsearch.c) .EX +#include #include #include #include @@ -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]); diff --git a/man/man3/fread.3 b/man/man3/fread.3 index 9ad56580c..1d6763254 100644 --- a/man/man3/fread.3 +++ b/man/man3/fread.3 @@ -106,6 +106,7 @@ Class: 0x02 \& .\" SRC BEGIN (fread.c) .EX +#include #include #include \& @@ -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); } diff --git a/man/man3/regex.3 b/man/man3/regex.3 index f6dc532f2..4b8376fae 100644 --- a/man/man3/regex.3 +++ b/man/man3/regex.3 @@ -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 #include #include #include @@ -381,7 +382,7 @@ int main(void) printf("Matches:\[rs]n"); \& for (unsigned int i = 0; ; i++) { - if (regexec(®ex, s, _Countof(pmatch), pmatch, 0)) + if (regexec(®ex, s, countof(pmatch), pmatch, 0)) break; \& off = pmatch[0].rm_so + (s \- str); diff --git a/man/man3/strncat.3 b/man/man3/strncat.3 index 4066ae4b1..bc0775676 100644 --- a/man/man3/strncat.3 +++ b/man/man3/strncat.3 @@ -90,6 +90,7 @@ Shlemiel the painter .SH EXAMPLES .\" SRC BEGIN (strncat.c) .EX +#include #include #include #include @@ -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 diff --git a/man/man7/string_copying.7 b/man/man7/string_copying.7 index 1a0e760a8..05d8536a6 100644 --- a/man/man7/string_copying.7 +++ b/man/man7/string_copying.7 @@ -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);