- #10 NULL redefinition warnings (fixed)
v0.5 - unreleased
-Implementations for <inttypes.h>, <errno.h>, and most parts of
-<stdio.h>.
+Implementations for <inttypes.h>, <errno.h>, most parts of <stdio.h>,
+and strerror() from <string.h>.
Still no locale / wide-char support. Enabled all GCC compiler warnings I
could find, and fixed everything that threw a warning. (You see this,
maintainers of Open Source software? No warnings whatsoever. Stop telling
return &_PDCLIB_errno;
}
+/* TODO: Doing this via a static array is not the way to do it. */
+char const * _PDCLIB_errno_texts[] = {
+ "",
+ "ERANGE (Range error)",
+ "EDOM (Domain error)",
+ "EIO (I/O error)",
+ "EUNKNOWN (Unknown error)",
+ "EINVAL (Invalid parameter value)",
+ "ERETRY (I/O retries exceeded)"
+};
+
#endif
#ifdef TEST
#ifndef REGTEST
+#include <errno.h>
+
+/* 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;
}
--- /dev/null
+/* $Id$ */
+
+/* strerror( int )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <string.h>
+
+#ifndef REGTEST
+
+/* TODO: Doing this via a static array is not the way to do it. */
+char * strerror( int errnum )
+{
+ return (char *)_PDCLIB_errno_texts[ errnum ];
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+#include <stdio.h>
+#include <errno.h>
+
+int main( void )
+{
+ TESTCASE( strerror( ERANGE ) != strerror( EDOM ) );
+ return TEST_RESULTS;
+}
+#endif
/* Map an error number to a (locale-specific) error message string. Error
numbers are typically errno values, but any number is mapped to a message.
TODO: PDCLib does not yet support locales.
- TODO: strerror() not yet implemented.
-char * strerror( int errnum );
*/
+char * strerror( int errnum );
/* Returns the length of the string s (excluding terminating '\0').
*/
#define _PDCLIB_EINVAL 5
/* Used in the example implementation for "I/O retries exceeded". */
#define _PDCLIB_ERETRY 6
+/* One larger than the largest used errno */
+#define _PDCLIB_EMAX 7
+/* TODO: Doing this via a static array is not the way to do it. */
+char const * _PDCLIB_errno_texts[ _PDCLIB_EMAX ];
static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
-/* FIXME: serr should handle one character. Buffering on out / in? */
static struct _PDCLIB_file_t _PDCLIB_serr = { 2, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_serr_ungetbuf, _IONBF | _PDCLIB_FWRITE, NULL, NULL };
static struct _PDCLIB_file_t _PDCLIB_sout = { 1, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sout_ungetbuf, _IOLBF | _PDCLIB_FWRITE, NULL, &_PDCLIB_serr };
static struct _PDCLIB_file_t _PDCLIB_sin = { 0, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sin_ungetbuf, _IOLBF | _PDCLIB_FREAD, NULL, &_PDCLIB_sout };