Module Name: src Committed By: rillig Date: Thu Feb 15 22:48:58 UTC 2024
Modified Files: src/common/lib/libutil: snprintb.c src/lib/libutil: snprintb.3 Log Message: snprintb: rename buflen to bufsize, following the wording in snprintf To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/common/lib/libutil/snprintb.c cvs rdiff -u -r1.30 -r1.31 src/lib/libutil/snprintb.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/lib/libutil/snprintb.c diff -u src/common/lib/libutil/snprintb.c:1.23 src/common/lib/libutil/snprintb.c:1.24 --- src/common/lib/libutil/snprintb.c:1.23 Thu Feb 15 22:37:10 2024 +++ src/common/lib/libutil/snprintb.c Thu Feb 15 22:48:58 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: snprintb.c,v 1.23 2024/02/15 22:37:10 rillig Exp $ */ +/* $NetBSD: snprintb.c,v 1.24 2024/02/15 22:48:58 rillig Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ # include <sys/cdefs.h> # if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: snprintb.c,v 1.23 2024/02/15 22:37:10 rillig Exp $"); +__RCSID("$NetBSD: snprintb.c,v 1.24 2024/02/15 22:48:58 rillig Exp $"); # endif # include <sys/types.h> @@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.23 2024 # include <errno.h> # else /* ! _KERNEL */ # include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.23 2024/02/15 22:37:10 rillig Exp $"); +__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.24 2024/02/15 22:48:58 rillig Exp $"); # include <sys/param.h> # include <sys/inttypes.h> # include <sys/systm.h> @@ -60,7 +60,7 @@ __KERNEL_RCSID(0, "$NetBSD: snprintb.c,v # ifndef HAVE_SNPRINTB_M int -snprintb_m(char *buf, size_t buflen, const char *bitfmt, uint64_t val, +snprintb_m(char *buf, size_t bufsize, const char *bitfmt, uint64_t val, size_t l_max) { char *bp = buf, *s_bp = NULL; @@ -75,7 +75,7 @@ snprintb_m(char *buf, size_t buflen, con * For safety; no other *s*printf() do this, but in the kernel * we don't usually check the return value */ - (void)memset(buf, 0, buflen); + (void)memset(buf, 0, bufsize); #endif /* _KERNEL */ ch = *bitfmt++; @@ -95,18 +95,18 @@ snprintb_m(char *buf, size_t buflen, con /* Reserve space for trailing blank line if needed */ if (l_max > 0) - buflen--; + bufsize--; - t_len = snprintf(bp, buflen, sbase, (uintmax_t)val); + t_len = snprintf(bp, bufsize, sbase, (uintmax_t)val); if (t_len < 0) goto internal; v_len = l_len = t_len; - if ((size_t)t_len < buflen) + if ((size_t)t_len < bufsize) bp += t_len; else - bp += buflen - 1; + bp += bufsize - 1; /* * If the value we printed was 0 and we're using the old-style format, @@ -116,7 +116,7 @@ snprintb_m(char *buf, size_t buflen, con goto terminate; #define STORE(c) do { l_len++; \ - if ((size_t)(++t_len) < buflen) \ + if ((size_t)(++t_len) < bufsize) \ *bp++ = (c); \ } while ( /* CONSTCOND */ 0) @@ -127,8 +127,8 @@ snprintb_m(char *buf, size_t buflen, con bitfmt = s_fmt; \ } \ STORE('>'); STORE('\0'); \ - if ((size_t)t_len < buflen) \ - snprintf(bp, buflen - t_len, sbase, (uintmax_t)val);\ + if ((size_t)t_len < bufsize) \ + snprintf(bp, bufsize - t_len, sbase, (uintmax_t)val);\ t_len += v_len; l_len = v_len; bp += v_len; \ } while ( /* CONSTCOND */ 0) @@ -168,12 +168,12 @@ snprintb_m(char *buf, size_t buflen, con } #define FMTSTR(sb, f) \ do { \ - f_len = snprintf(bp, buflen - t_len, sb, (uintmax_t)f); \ + f_len = snprintf(bp, bufsize - t_len, sb, (uintmax_t)f); \ if (f_len < 0) \ goto internal; \ t_len += f_len; \ l_len += f_len; \ - if ((size_t)t_len < buflen) \ + if ((size_t)t_len < bufsize) \ bp += f_len; \ } while (/*CONSTCOND*/0) @@ -279,7 +279,7 @@ terminate: if (l_max != 0) { STORE('\0'); t_len--; - buf[buflen] = '\0'; + buf[bufsize] = '\0'; } return t_len; internal: @@ -290,9 +290,9 @@ internal: } int -snprintb(char *buf, size_t buflen, const char *bitfmt, uint64_t val) +snprintb(char *buf, size_t bufsize, const char *bitfmt, uint64_t val) { - return snprintb_m(buf, buflen, bitfmt, val, 0); + return snprintb_m(buf, bufsize, bitfmt, val, 0); } # endif /* ! HAVE_SNPRINTB_M */ #endif /* ! _STANDALONE */ Index: src/lib/libutil/snprintb.3 diff -u src/lib/libutil/snprintb.3:1.30 src/lib/libutil/snprintb.3:1.31 --- src/lib/libutil/snprintb.3:1.30 Thu Feb 1 22:18:34 2024 +++ src/lib/libutil/snprintb.3 Thu Feb 15 22:48:58 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: snprintb.3,v 1.30 2024/02/01 22:18:34 rillig Exp $ +.\" $NetBSD: snprintb.3,v 1.31 2024/02/15 22:48:58 rillig Exp $ .\" .\" Copyright (c) 1998 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 1, 2024 +.Dd February 15, 2024 .Dt SNPRINTB 3 .Os .Sh NAME @@ -39,9 +39,9 @@ .Sh SYNOPSIS .In util.h .Ft int -.Fn "snprintb" "char *buf" "size_t buflen" "const char *fmt" "uint64_t val" +.Fn "snprintb" "char *buf" "size_t bufsize" "const char *fmt" "uint64_t val" .Ft int -.Fn "snprintb_m" "char *buf" "size_t buflen" "const char *fmt" "uint64_t val" \ +.Fn "snprintb_m" "char *buf" "size_t bufsize" "const char *fmt" "uint64_t val" \ "size_t max" .Sh DESCRIPTION The @@ -54,7 +54,7 @@ It formats the integer into the buffer .Fa buf , of size -.Fa buflen , +.Fa bufsize , using a specified radix and an interpretation of the bits within that integer as though they were flags or groups of bits. The buffer is always @@ -283,10 +283,10 @@ total number of bytes. .Sh EXAMPLES Two examples of the old formatting style: .Bd -literal -offset indent -snprintb(buf, buflen, "\e10\e2BITTWO\e1BITONE", 3) +snprintb(buf, bufsize, "\e10\e2BITTWO\e1BITONE", 3) \(rA "03<BITTWO,BITONE>" -snprintb(buf, buflen, +snprintb(buf, bufsize, "\e20" "\ex10NOTBOOT" "\ex0f""FPP" "\ex0eSDVMA" "\ex0cVIDEO" "\ex0bLORES" "\ex0a""FPA" "\ex09""DIAG" @@ -298,7 +298,7 @@ snprintb(buf, buflen, .Pp An example of the new formatting style: .Bd -literal -offset indent -snprintb(buf, buflen, +snprintb(buf, bufsize, "\e177\e020" "b\e0LSB\e0" "b\e1BITONE\e0" "f\e4\e4NIBBLE2\e0" @@ -310,7 +310,7 @@ snprintb(buf, buflen, .Pp The same example using snprintb_m: .Bd -literal -offset indent -snprintb_m(buf, buflen, +snprintb_m(buf, bufsize, "\e177\e020" "b\e0LSB\e0" "b\e1BITONE\e0" "f\e4\e4NIBBLE2\e0" "f\ex10\e4BURST\e0" "=\e4FOUR\e0" "=\exf""FIFTEEN\e0" @@ -373,10 +373,10 @@ multibit field formatting with a default ":\e074" "ALIGN=256PB\e0" \e "*" "ALIGN=2^%ju\e0" -snprintb(buf, buflen, MAP_FMT, 0x0d001234) +snprintb(buf, bufsize, MAP_FMT, 0x0d001234) \(rA "0xd001234<COPY,FIXED,RENAME,HASSEMAPHORE,ANONYMOUS,ALIGN=8KB>" -snprintb(buf, buflen, MAP_FMT, 0x2e000000) +snprintb(buf, bufsize, MAP_FMT, 0x2e000000) \(rA "0xd001234<0x2e000000<FILE,ALIGN=2^46>" .Ed .Sh ERRORS