aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-07-10 07:41:34 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-07-10 07:41:34 +0000
commite434ca4b43de6116fc215552833b402b9ac2fb62 (patch)
treea3910e78bfc4ee4c155247413662646d59c5a3d4
parentac8ec11ca02a5dd49390074db243a7910d1c5782 (diff)
downloadbusybox-w32-e434ca4b43de6116fc215552833b402b9ac2fb62.tar.gz
busybox-w32-e434ca4b43de6116fc215552833b402b9ac2fb62.tar.bz2
busybox-w32-e434ca4b43de6116fc215552833b402b9ac2fb62.zip
Add itoa and utoa to see what Denis Vlasenko thinks.
git-svn-id: svn://busybox.net/trunk/busybox@15673 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--libbb/xfuncs.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 684d0a4fb..00cacaadf 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -229,4 +229,53 @@ int wait4pid(int pid)
229 if (WIFSIGNALED(status)) return WTERMSIG(status); 229 if (WIFSIGNALED(status)) return WTERMSIG(status);
230 return 0; 230 return 0;
231} 231}
232#endif 232#endif
233
234#ifdef L_itoa
235// Largest 32 bit integer is -2 billion plus null terminator.
236// Int should always be 32 bits on a Unix-oid system, see
237// http://www.unix.org/whitepapers/64bit.html
238static char local_buf[12];
239
240void utoa_to_buf(unsigned n, char *buf, int buflen)
241{
242 int i, out = 0;
243 for (i=1000000000; i; i/=10) {
244 int res = n/i;
245
246 if (res || out || i == 1) {
247 out++;
248 n -= res*i;
249 *buf++ = '0' + res;
250 }
251 }
252 *buf = 0;
253}
254
255// Note: uses static buffer, calling it twice in a row will overwrite.
256
257char *utoa(unsigned n)
258{
259 utoa_to_buf(n, local_buf, sizeof(local_buf));
260
261 return local_buf;
262}
263
264void itoa_to_buf(int n, char *buf, int buflen)
265{
266 if (n<0) {
267 n = -n;
268 *buf++ = '-';
269 }
270 utoa_to_buf((unsigned)n, buf, buflen);
271}
272
273// Note: uses static buffer, calling it twice in a row will overwrite.
274
275char *itoa(int n)
276{
277 itoa_to_buf(n, local_buf, sizeof(local_buf));
278
279 return local_buf;
280}
281#endif