Simple routine to convert long to string.

This commit is contained in:
haad 2010-12-14 01:01:40 +00:00
parent 2940dfac08
commit 01d7ba741b
2 changed files with 25 additions and 2 deletions

View File

@ -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 @@ strident_canon(char *s, size_t n)
}
*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';
}

View File

@ -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>
@ -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_ */