diff options
author | Jari Aalto <jari.aalto@cante.net> | 1999-02-19 17:11:39 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:52 +0000 |
commit | b72432fdcc59300c6fe7c9d6c8a31ad3447933f5 (patch) | |
tree | b9899162338c2ff3fd83a8aef8831cb119e85cd7 /lib/sh/itos.c | |
parent | bc4cd23ce958feda898c618215f94d8a4e8f4ffa (diff) | |
download | android_external_bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.gz android_external_bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.bz2 android_external_bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.zip |
Imported from ../bash-2.03.tar.gz.
Diffstat (limited to 'lib/sh/itos.c')
-rw-r--r-- | lib/sh/itos.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/sh/itos.c b/lib/sh/itos.c index 720e410..5105cb7 100644 --- a/lib/sh/itos.c +++ b/lib/sh/itos.c @@ -31,13 +31,16 @@ of an integer. 32 is larger than the string rep of 2^^31 - 1. */ #define MAX_INT_LEN 32 -/* Integer to string conversion. This conses the string; the - caller should free it. */ +/* Integer to string conversion. The caller passes the buffer and + the size. This should check for buffer underflow, but currently + does not. */ char * -itos (i) +inttostr (i, buf, len) int i; + char *buf; + int len; { - char buf[MAX_INT_LEN], *p, *ret; + char *p; int negative = 0; unsigned int ui; @@ -49,7 +52,7 @@ itos (i) ui = (unsigned int) i; - p = buf + MAX_INT_LEN - 2; + p = buf + len - 2; p[1] = '\0'; do @@ -59,6 +62,17 @@ itos (i) if (negative) *p-- = '-'; - ret = savestring (p + 1); - return (ret); + return (p + 1); +} + +/* Integer to string conversion. This conses the string; the + caller should free it. */ +char * +itos (i) + int i; +{ + char *p, lbuf[MAX_INT_LEN]; + + p = inttostr (i, lbuf, sizeof(lbuf)); + return (savestring (p)); } |