Path: blob/master/waterbox/libc/functions/_PDCLIB/_PDCLIB_atomax.c
2 views
/* _PDCLIB_atomax( const char * )12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#ifndef REGTEST7#include "_PDCLIB_int.h"8#include <string.h>9#include <ctype.h>1011_PDCLIB_intmax_t _PDCLIB_atomax( const char * s )12{13_PDCLIB_intmax_t rc = 0;14char sign = '+';15const char * x;16/* TODO: In other than "C" locale, additional patterns may be defined */17while ( isspace( *s ) ) ++s;18if ( *s == '+' ) ++s;19else if ( *s == '-' ) sign = *(s++);20/* TODO: Earlier version was missing tolower() but was not caught by tests */21while ( ( x = memchr( _PDCLIB_digits, tolower(*(s++)), 10 ) ) != NULL )22{23rc = rc * 10 + ( x - _PDCLIB_digits );24}25return ( sign == '+' ) ? rc : -rc;26}27#endif2829#ifdef TEST30#include "_PDCLIB_test.h"3132int main( void )33{34#ifndef REGTEST35/* basic functionality */36TESTCASE( _PDCLIB_atomax( "123" ) == 123 );37/* testing skipping of leading whitespace and trailing garbage */38TESTCASE( _PDCLIB_atomax( " \n\v\t\f123xyz" ) == 123 );39#endif40return TEST_RESULTS;41}4243#endif444546