From c6218dbae579de0cd20f5a7f1e9877673e28225d Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 20 Dec 2000 22:52:58 +0000 Subject: A number of updates from Manuel Novoa III. Things look good... --- libc/misc/internals/lltostr.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 libc/misc/internals/lltostr.c (limited to 'libc/misc/internals/lltostr.c') diff --git a/libc/misc/internals/lltostr.c b/libc/misc/internals/lltostr.c new file mode 100644 index 000000000..2ce359615 --- /dev/null +++ b/libc/misc/internals/lltostr.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2000 Manuel Novoa III + * + * Note: buf is a pointer to the END of the buffer passed. + * Call like this: + * char buf[SIZE], *p; + * p = __lltostr(buf + sizeof(buf) - 1, ...) + * For long longs of 64 bits, appropriate buffer sizes are: + * base = 2 66 = 1 (possible -) sign + 64 digits + 1 nul + * base = 10 21 = 1 (possible -) sign + 19 digits + 1 nul + * base = 16 18 = 1 (possible -) sign + 16 hex digits + 1 nul + */ + +extern char *__ulltostr(char *buf, unsigned long long uval, int base, + int uppercase); + +char *__lltostr(char *buf, long long val, int base, int uppercase) +{ + unsigned long long uval; + char *pos; + int negative; + + negative = 0; + if (val < 0) { + negative = 1; + uval = ((unsigned long long)(-(1+val))) + 1; + } else { + uval = val; + } + + + pos = __ulltostr(buf, uval, base, uppercase); + + if (pos && negative) { + *--pos = '-'; + } + + return pos; +} -- cgit v1.2.3