Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/ddb ddb(9): New db_num_to_strbuf.



details:   https://anonhg.NetBSD.org/src/rev/c04778693849
branches:  trunk
changeset: 369768:c04778693849
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Aug 30 22:37:03 2022 +0000

description:
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.

diffstat:

 sys/ddb/db_lex.c |  23 +++++++++++++++--------
 sys/ddb/db_lex.h |   3 ++-
 2 files changed, 17 insertions(+), 9 deletions(-)

diffs (66 lines):

diff -r 2dfab4a8ebc2 -r c04778693849 sys/ddb/db_lex.c
--- a/sys/ddb/db_lex.c  Tue Aug 30 22:36:48 2022 +0000
+++ b/sys/ddb/db_lex.c  Tue Aug 30 22:37:03 2022 +0000
@@ -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,17 +172,24 @@
         */
        static char buf[25];
 
-       if (db_radix == 16)
-               snprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "x", val);
-       else if (db_radix == 8)
-               snprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "o", val);
-       else
-               snprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "u", val);
+       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, len, "%" DDB_EXPR_FMT "x", val);
+       else if (db_radix == 8)
+               snprintf(buf, len, "%" DDB_EXPR_FMT "o", val);
+       else
+               snprintf(buf, len, "%" DDB_EXPR_FMT "u", val);
+}
+
+void
 db_flush_lex(void)
 {
 
diff -r 2dfab4a8ebc2 -r c04778693849 sys/ddb/db_lex.h
--- a/sys/ddb/db_lex.h  Tue Aug 30 22:36:48 2022 +0000
+++ b/sys/ddb/db_lex.h  Tue Aug 30 22:37:03 2022 +0000
@@ -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 **);



Home | Main Index | Thread Index | Old Index