[affinityos commit] r5 - in trunk: include/libc lib/libc

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 30, 2006, 5:38:51 AM7/30/06
to affini...@googlegroups.com
Author: ownthebox.net
Date: Sun Jul 30 02:37:39 2006
New Revision: 5

Modified:
trunk/include/libc/stdlib.h
trunk/lib/libc/stdlib.c

Log:
Updated code.

Modified: trunk/include/libc/stdlib.h
==============================================================================
--- trunk/include/libc/stdlib.h (original)
+++ trunk/include/libc/stdlib.h Sun Jul 30 02:37:39 2006
@@ -12,7 +12,7 @@
{
#endif

-
+void itoa(char* pszBuffer, int iBase, int iNum);

#ifdef __cplusplus
}

Modified: trunk/lib/libc/stdlib.c
==============================================================================
--- trunk/lib/libc/stdlib.c (original)
+++ trunk/lib/libc/stdlib.c Sun Jul 30 02:37:39 2006
@@ -5,3 +5,45 @@
*/

#include <stdlib.h>
+
+void itoa(char* pszBuffer, int iBase, int iNum)
+{
+ char* pszTemp = pszBuffer;
+ char* pszBuf1;
+ char* pszBuf2;
+ unsigned long ulNum = iNum;
+ int iDivisor = 10;
+
+ if (iBase == 'd' && iNum < 0)
+ {
+ *pszTemp++ = '-';
+ pszBuffer++;
+ ulNum = -iNum;
+ }
+ else if (iBase == 'x')
+ {
+ iDivisor = 16;
+ }
+
+ do
+ {
+ int iRemainder = ulNum % iDivisor;
+
+ *pszTemp++ = (iRemainder < 10) ? iRemainder + '0' : iRemainder + 'a' - 10;
+ }
+ while (ulNum /= iDivisor);
+
+ *pszTemp = 0;
+
+ pszBuf1 = pszBuffer;
+ pszBuf2 = pszTemp - 1;
+
+ while (pszBuf1 < pszBuf2)
+ {
+ char pszTmp = *pszBuf1;
+ *pszBuf1 = *pszBuf2;
+ *pszBuf2 = pszTmp;
+ pszBuf1++;
+ pszBuf2--;
+ }
+}

Reply all
Reply to author
Forward
0 new messages