Module Name:    src
Committed By:   riastradh
Date:           Tue Aug 30 22:37:03 UTC 2022

Modified Files:
        src/sys/ddb: db_lex.c db_lex.h

Log Message:
ddb(9): New db_num_to_strbuf.

Like db_num_to_str, but writes to caller-provided buffer instead of
returning pointer to static storage.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/ddb/db_lex.c
cvs rdiff -u -r1.16 -r1.17 src/sys/ddb/db_lex.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_lex.c
diff -u src/sys/ddb/db_lex.c:1.26 src/sys/ddb/db_lex.c:1.27
--- src/sys/ddb/db_lex.c:1.26	Wed Jul 29 23:29:42 2020
+++ src/sys/ddb/db_lex.c	Tue Aug 30 22:37:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_lex.c,v 1.26 2020/07/29 23:29:42 uwe Exp $	*/
+/*	$NetBSD: db_lex.c,v 1.27 2022/08/30 22:37:03 riastradh Exp $	*/
 
 /*
  * Mach Operating System
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.26 2020/07/29 23:29:42 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.27 2022/08/30 22:37:03 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -172,14 +172,21 @@ db_num_to_str(db_expr_t val)
 	 */
 	static char buf[25];
 
+	db_num_to_strbuf(val, buf, sizeof(buf));
+
+	return (buf);
+}
+
+void
+db_num_to_strbuf(db_expr_t val, char *buf, size_t len)
+{
+
 	if (db_radix == 16)
-		snprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "x", val);
+		snprintf(buf, len, "%" DDB_EXPR_FMT "x", val);
 	else if (db_radix == 8)
-		snprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "o", val);
+		snprintf(buf, len, "%" DDB_EXPR_FMT "o", val);
 	else
-		snprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "u", val);
-
-	return (buf);
+		snprintf(buf, len, "%" DDB_EXPR_FMT "u", val);
 }
 
 void

Index: src/sys/ddb/db_lex.h
diff -u src/sys/ddb/db_lex.h:1.16 src/sys/ddb/db_lex.h:1.17
--- src/sys/ddb/db_lex.h:1.16	Wed Jul 29 23:29:42 2020
+++ src/sys/ddb/db_lex.h	Tue Aug 30 22:37:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_lex.h,v 1.16 2020/07/29 23:29:42 uwe Exp $	*/
+/*	$NetBSD: db_lex.h,v 1.17 2022/08/30 22:37:03 riastradh Exp $	*/
 
 /*
  * Mach Operating System
@@ -34,6 +34,7 @@
  */
 void	db_flush_lex(void);
 char   *db_num_to_str(db_expr_t);
+void	db_num_to_strbuf(db_expr_t, char *, size_t);
 int	db_read_line(void);
 void	db_set_line(const char *, const char *);
 void	db_get_line(const char **, const char **);

Reply via email to