--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* _PDCLIB_atomax( const char * )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <_PDCLIB_int.h>
+#include <string.h>
+#include <ctype.h>
+
+_PDCLIB_intmax_t _PDCLIB_atomax( const char * s )
+{
+ _PDCLIB_intmax_t rc = 0;
+ char sign = '+';
+ const char * x;
+ /* TODO: In other than "C" locale, additional patterns may be defined */
+ while ( isspace( *s ) ) ++s;
+ if ( *s == '+' ) ++s;
+ else if ( *s == '-' ) sign = *(s++);
+ while ( ( x = memchr( _PDCLIB_digits, *(s++), 10 ) ) != NULL )
+ {
+ rc = rc * 10 + ( x - _PDCLIB_digits );
+ }
+ return ( sign == '+' ) ? rc : -rc;
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main()
+{
+ BEGIN_TESTS;
+ /* basic functionality */
+ TESTCASE( _PDCLIB_atomax( "123" ) == 123 );
+ /* testing skipping of leading whitespace and trailing garbage */
+ TESTCASE( _PDCLIB_atomax( " \n\v\t\f123xyz" ) == 123 );
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* _PDCLIB_digits
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+char _PDCLIB_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main()
+{
+ BEGIN_TESTS;
+ /* no tests for raw data */
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* atoi( const char * )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <_PDCLIB_int.h>
+
+int atoi( const char * s )
+{
+ return (int) _PDCLIB_atomax( s );
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main()
+{
+ BEGIN_TESTS;
+ /* no tests for a simple wrapper */
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* atol( const char * )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <_PDCLIB_int.h>
+
+long int atol( const char * s )
+{
+ return (long int) _PDCLIB_atomax( s );
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main()
+{
+ BEGIN_TESTS;
+ /* no tests for a simple wrapper */
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* atoll( const char * )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <_PDCLIB_int.h>
+
+long long int atoll( const char * s )
+{
+ return (long long int) _PDCLIB_atomax( s );
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main()
+{
+ BEGIN_TESTS;
+ /* no tests for a simple wrapper */
+ return TEST_RESULTS;
+}
+
+#endif
#if _PDCLIB_LONG_BYTES == 4
#define _PDCLIB_LONG_MAX 0x7fffffffL
#define _PDCLIB_LONG_MIN (-0x7fffffffL - 1L)
-#define _PDCLIB_ULONG_MAX 0xffffffffUL
+#define _PDCLIB_ULONG_MAX 0xffffffffUL
#elif _PDCLIB_LONG_BYTES == 8
#define _PDCLIB_LONG_MAX 0x7fffffffffffffffL
#define _PDCLIB_LONG_MIN (-0x7fffffffffffffffL - 1L)
#define _PDCLIB_UINTMAX_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTMAX ), _MAX )
#define _PDCLIB_INTMAX_C( value ) concat( value, _PDCLIB_INTMAX_LITERAL )
#define _PDCLIB_UINTMAX_C( value ) concat( value, concat( u, _PDCLIB_INTMAX_LITERAL ) )
+
+/* -------------------------------------------------------------------------- */
+/* Declaration of helper functions (implemented in functions/_PDCLIB). */
+/* -------------------------------------------------------------------------- */
+
+/* This is the main function called by atoi(), atol() and atoll(). */
+_PDCLIB_intmax_t _PDCLIB_atomax( const char * s );
+
+/* Digits array used by various integer conversion functions in <stdlib.h> */
+extern char _PDCLIB_digits[];