]> pd.if.org Git - pdclib/blobdiff - functions/stdio/perror.c
Ad-hoc solutions for perror() and strerror().
[pdclib] / functions / stdio / perror.c
index d94746cdb2c217399e61e82c45d583a280d9d511..609562a8e46a783a89420808117163d6d8ce5c5e 100644 (file)
@@ -1,26 +1,37 @@
-// ----------------------------------------------------------------------------
-// $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 <stdio.h>
+
+#ifndef REGTEST
+
+#include <errno.h>
+
+/* 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>
+
+int main( void )
+{
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
+}
+
+#endif