X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fperror.c;h=bf3b3afee1c1bf0028218f657263853c0ffcc7a6;hb=a7a8d2f1c85c2d7760d4d3479e90466cc3a81b04;hp=c59ca0b290a582934f50c3b4a467002915a4a527;hpb=e5112b619d1aae8ffc439389cfcbd3b2b4bd2454;p=pdclib diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index c59ca0b..bf3b3af 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -10,9 +10,16 @@ #ifndef REGTEST +#include + +/* TODO: Doing this via a static array is not the way to do it. */ void perror( const char * s ) { - /* TODO: Implement. */ + if ( ( s != NULL ) && ( s[0] != '\n' ) ) + { + fprintf( stderr, "%s: ", s ); + } + fprintf( stderr, "%s\n", _PDCLIB_errno_texts[ errno ] ); return; } @@ -20,10 +27,24 @@ void perror( const char * s ) #ifdef TEST #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; }