Source-Changes-HG archive

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

[src/trunk]: src/external/cddl/osnet/sys Simple routine to convert long to st...



details:   https://anonhg.NetBSD.org/src/rev/39192a9c53db
branches:  trunk
changeset: 759624:39192a9c53db
user:      haad <haad%NetBSD.org@localhost>
date:      Tue Dec 14 01:01:40 2010 +0000

description:
Simple routine to convert long to string.

diffstat:

 external/cddl/osnet/sys/kern/string.c |  24 +++++++++++++++++++++++-
 external/cddl/osnet/sys/sys/string.h  |   3 ++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diffs (51 lines):

diff -r f338da1884e7 -r 39192a9c53db external/cddl/osnet/sys/kern/string.c
--- a/external/cddl/osnet/sys/kern/string.c     Tue Dec 14 01:00:26 2010 +0000
+++ b/external/cddl/osnet/sys/kern/string.c     Tue Dec 14 01:01:40 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: string.c,v 1.1 2009/08/07 20:57:57 haad Exp $  */
+/*     $NetBSD: string.c,v 1.2 2010/12/14 01:01:40 haad Exp $  */
 
 /*
  * CDDL HEADER START
@@ -71,3 +71,25 @@
        }
        *s = 0;
 }
+
+/*
+ * Simple-minded conversion of a long into a null-terminated character
+ * string.  Caller must ensure there's enough space to hold the result.
+ */
+void
+numtos(unsigned long num, char *s)
+{
+       char prbuf[40];
+
+       char *cp = prbuf;
+
+       do {
+               *cp++ = "0123456789"[num % 10];
+               num /= 10;
+       } while (num);
+
+       do {
+               *s++ = *--cp;
+       } while (cp > prbuf);
+       *s = '\0';
+}
diff -r f338da1884e7 -r 39192a9c53db external/cddl/osnet/sys/sys/string.h
--- a/external/cddl/osnet/sys/sys/string.h      Tue Dec 14 01:00:26 2010 +0000
+++ b/external/cddl/osnet/sys/sys/string.h      Tue Dec 14 01:01:40 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: string.h,v 1.3 2010/02/21 01:46:36 darran Exp $        */
+/*     $NetBSD: string.h,v 1.4 2010/12/14 01:01:41 haad Exp $  */
 
 /*-
  * Copyright (c) 2007 Pawel Jakub Dawidek <pjd%FreeBSD.org@localhost>
@@ -33,5 +33,6 @@
 
 char   *strpbrk(const char *, const char *);
 void    strident_canon(char *s, size_t n);
+void   numtos(unsigned long num, char *s);
 
 #endif /* _OPENSOLARIS_SYS_STRING_H_ */



Home | Main Index | Thread Index | Old Index