X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fperror.c;h=a5185980dbbb978324858d7732b1d56d856dda79;hb=d6f1494a4f38a212b29a13ee713885058dcf0fe7;hp=609562a8e46a783a89420808117163d6d8ce5c5e;hpb=4116251e9bb6c386580d71d8c4afd2d0d08c6096;p=pdclib diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index 609562a..a518598 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* perror( const char * ) This file is part of the Public Domain C Library (PDCLib). @@ -11,6 +9,7 @@ #ifndef REGTEST #include +#include /* TODO: Doing this via a static array is not the way to do it. */ void perror( const char * s ) @@ -19,18 +18,39 @@ void perror( const char * s ) { fprintf( stderr, "%s: ", s ); } - fprintf( stderr, "%s\n", _PDCLIB_errno_texts[ errno ] ); + if ( errno >= _PDCLIB_ERRNO_MAX ) + { + fprintf( stderr, "Unknown error\n" ); + } + else + { + fprintf( stderr, "%s\n", _PDCLIB_lconv._PDCLIB_errno_texts[errno] ); + } return; } #endif #ifdef TEST -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" +#include +#include +#include int main( void ) { - TESTCASE( NO_TESTDRIVER ); + FILE * fh; + unsigned long long max = ULLONG_MAX; + char buffer[100]; + sprintf( buffer, "%llu", max ); + TESTCASE( ( fh = freopen( testfile, "wb+", stderr ) ) != NULL ); + TESTCASE( strtol( buffer, NULL, 10 ) == LONG_MAX ); + perror( "Test" ); + rewind( fh ); + TESTCASE( fread( buffer, 1, 7, fh ) == 7 ); + TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 ); + TESTCASE( fclose( fh ) == 0 ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; }