3 /* perror( const char * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
16 /* TODO: Doing this via a static array is not the way to do it. */
17 void perror( const char * s )
19 if ( ( s != NULL ) && ( s[0] != '\n' ) )
21 fprintf( stderr, "%s: ", s );
23 if ( errno >= _PDCLIB_ERRNO_MAX )
25 fprintf( stderr, "Unknown error\n" );
29 fprintf( stderr, "%s\n", _PDCLIB_lconv._PDCLIB_errno_texts[errno] );
37 #include <_PDCLIB_test.h>
45 unsigned long long max = ULLONG_MAX;
47 sprintf( buffer, "%llu", max );
48 TESTCASE( ( fh = freopen( testfile, "wb+", stderr ) ) != NULL );
49 TESTCASE( strtol( buffer, NULL, 10 ) == LONG_MAX );
52 TESTCASE( fread( buffer, 1, 7, fh ) == 7 );
53 TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 );
54 TESTCASE( fclose( fh ) == 0 );
55 TESTCASE( remove( testfile ) == 0 );