X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=functions%2Fstdio%2Fperror.c;h=bf3b3afee1c1bf0028218f657263853c0ffcc7a6;hb=2612fba05258dfde899375db0aa88e65c337395d;hp=d85cd647440cbdfcd8e75acb2052a1dc80121877;hpb=758f3c180e9f4548d0834dadfe3d126ca04be4f9;p=fw%2Fpdclib diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index d85cd64..bf3b3af 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -1,26 +1,51 @@ -/* ---------------------------------------------------------------------------- - * $Id$ - * ---------------------------------------------------------------------------- - * Public Domain C Library - http://pdclib.sourceforge.net - * This code is Public Domain. Use, modify, and redistribute at will. - * --------------------------------------------------------------------------*/ +/* $Id$ */ -void perror( const char * s ) { /* TODO */ }; +/* perror( const char * ) -/* PDPC code - unreviewed + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +#include + +/* TODO: Doing this via a static array is not the way to do it. */ +void perror( const char * s ) { - if ((s != NULL) && (*s != '\0')) - { - printf("%s: "); - } - if (errno == 0) - { - printf("No error has occurred\n"); - } - else + if ( ( s != NULL ) && ( s[0] != '\n' ) ) { - printf("An error has occurred\n"); + fprintf( stderr, "%s: ", s ); } + fprintf( stderr, "%s\n", _PDCLIB_errno_texts[ errno ] ); return; } -*/ + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> +#include +#include +#include + +int main( void ) +{ + 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; +} + +#endif