From: solar Date: Thu, 30 Dec 2010 22:43:20 +0000 (+0000) Subject: Addressed ticket #40 (non-standard errno values). X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=ce0e5d8cd76b50f239fb8e95170502b146247b35 Addressed ticket #40 (non-standard errno values). --- diff --git a/functions/_PDCLIB/errno.c b/functions/_PDCLIB/errno.c index 0c959b7..ba01c35 100644 --- a/functions/_PDCLIB/errno.c +++ b/functions/_PDCLIB/errno.c @@ -18,17 +18,6 @@ int * _PDCLIB_errno_func() 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 diff --git a/functions/_PDCLIB/prepread.c b/functions/_PDCLIB/prepread.c index ef2f70e..9111ff4 100644 --- a/functions/_PDCLIB/prepread.c +++ b/functions/_PDCLIB/prepread.c @@ -17,7 +17,11 @@ int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ) ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) || ! ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_FRW ) ) ) { - _PDCLIB_errno = _PDCLIB_EIO; + /* Function called on illegal (e.g. output) stream. + See comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ + _PDCLIB_errno = _PDCLIB_ERROR; stream->status |= _PDCLIB_ERRORFLAG; return EOF; } diff --git a/functions/_PDCLIB/prepwrite.c b/functions/_PDCLIB/prepwrite.c index c5a4c12..148e1c1 100644 --- a/functions/_PDCLIB/prepwrite.c +++ b/functions/_PDCLIB/prepwrite.c @@ -14,7 +14,11 @@ int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ) ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) || ! ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) ) ) { - _PDCLIB_errno = _PDCLIB_EIO; + /* Function called on illegal (e.g. input) stream. + See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ + _PDCLIB_errno = _PDCLIB_ERROR; stream->status |= _PDCLIB_ERRORFLAG; return EOF; } diff --git a/functions/stdio/fclose.c b/functions/stdio/fclose.c index 3a25b52..81b57c4 100644 --- a/functions/stdio/fclose.c +++ b/functions/stdio/fclose.c @@ -58,7 +58,10 @@ int fclose( struct _PDCLIB_file_t * stream ) previous = current; current = current->next; } - _PDCLIB_errno = _PDCLIB_EIO; + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ + _PDCLIB_errno = _PDCLIB_ERROR; return -1; } diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index bf3b3af..23ce68b 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -11,6 +11,7 @@ #ifndef REGTEST #include +#include /* TODO: Doing this via a static array is not the way to do it. */ void perror( const char * s ) @@ -19,7 +20,14 @@ void perror( const char * s ) { fprintf( stderr, "%s: ", s ); } - fprintf( stderr, "%s\n", _PDCLIB_errno_texts[ errno ] ); + if ( errno >= _PDCLIB_ERRNO_MAX ) + { + fprintf( stderr, "Unknown error\n" ); + } + else + { + fprintf( stderr, "%s\n", _PDCLIB_lconv._PDCLIB_errno_texts[errno] ); + } return; } diff --git a/functions/string/strerror.c b/functions/string/strerror.c index 89ebed0..b0ced5d 100644 --- a/functions/string/strerror.c +++ b/functions/string/strerror.c @@ -10,10 +10,19 @@ #ifndef REGTEST +#include + /* TODO: Doing this via a static array is not the way to do it. */ char * strerror( int errnum ) { - return (char *)_PDCLIB_errno_texts[ errnum ]; + if ( errnum == 0 || errnum >= _PDCLIB_ERRNO_MAX ) + { + return (char *)"Unknown error"; + } + else + { + return _PDCLIB_lconv._PDCLIB_errno_texts[errnum]; + } } #endif diff --git a/includes/locale.h b/includes/locale.h index 0277016..d849244 100644 --- a/includes/locale.h +++ b/includes/locale.h @@ -38,6 +38,7 @@ struct lconv { struct _PDCLIB_ctype_t * ctype; /* internal information */ + char * _PDCLIB_errno_texts[_PDCLIB_ERRNO_MAX]; /* strerror() / perror() */ char * decimal_point; /* decimal point character */ char * thousands_sep; /* character for seperating groups of digits */ char * grouping; /* string indicating the size of digit groups */ diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index 2d99b91..a46c2dc 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -407,25 +407,17 @@ void _PDCLIB_closeall( void ); /* errno */ /* -------------------------------------------------------------------------- */ +/* If PDCLib would call its error number "errno" directly, there would be no way + to catch its value from underlying system calls that also use it (i.e., POSIX + operating systems). That is why we use an internal name, providing a means to + access it through . +*/ extern int _PDCLIB_errno; -int * _PDCLIB_errno_func( void ); -/* ERANGE and EDOM are specified by the standard. */ -#define _PDCLIB_ERANGE 1 -#define _PDCLIB_EDOM 2 -/* Used in the example implementation for any kind of I/O error. */ -#define _PDCLIB_EIO 3 -/* Used in the example implementation for "unknown error". */ -#define _PDCLIB_EUNKNOWN 4 -/* Used in the example implementation for "invalid parameter value". */ -#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 ]; +/* A mechanism for delayed evaluation. (Not sure if this is really necessary, so + no detailed documentation on the "why".) +*/ +int * _PDCLIB_errno_func( void ); /* -------------------------------------------------------------------------- */ /* lookup tables */ diff --git a/platform/example/functions/_PDCLIB/fillbuffer.c b/platform/example/functions/_PDCLIB/fillbuffer.c index 8da93ad..a5520a3 100644 --- a/platform/example/functions/_PDCLIB/fillbuffer.c +++ b/platform/example/functions/_PDCLIB/fillbuffer.c @@ -41,15 +41,19 @@ int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) /* Reading error */ switch ( errno ) { + /* See comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EBADF: case EFAULT: case EINTR: case EINVAL: case EIO: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should probably be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } stream->status |= _PDCLIB_ERRORFLAG; diff --git a/platform/example/functions/_PDCLIB/flushbuffer.c b/platform/example/functions/_PDCLIB/flushbuffer.c index c2ac98d..e68c6c4 100644 --- a/platform/example/functions/_PDCLIB/flushbuffer.c +++ b/platform/example/functions/_PDCLIB/flushbuffer.c @@ -50,6 +50,10 @@ int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) /* Write error */ switch ( errno ) { + /* See <_PDCLIB_config.h>. There should be differenciated errno + handling here, possibly even a 1:1 mapping; but that is up + to the individual platform. + */ case EBADF: case EFAULT: case EFBIG: @@ -58,10 +62,11 @@ int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) case EIO: case ENOSPC: case EPIPE: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } stream->status |= _PDCLIB_ERRORFLAG; @@ -79,7 +84,10 @@ int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) return 0; } } - _PDCLIB_errno = _PDCLIB_ERETRY; + /* Number of retries exceeded. You probably want a different errno value + here. + */ + _PDCLIB_errno = _PDCLIB_ERROR; stream->status |= _PDCLIB_ERRORFLAG; /* Move unwritten remains to begin of buffer. */ stream->bufidx -= written; diff --git a/platform/example/functions/_PDCLIB/open.c b/platform/example/functions/_PDCLIB/open.c index 0230558..2098dd3 100644 --- a/platform/example/functions/_PDCLIB/open.c +++ b/platform/example/functions/_PDCLIB/open.c @@ -64,6 +64,9 @@ int _PDCLIB_open( char const * const filename, unsigned int mode ) { switch ( errno ) { + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EACCES: case EFAULT: case EINTR: @@ -80,9 +83,12 @@ int _PDCLIB_open( char const * const filename, unsigned int mode ) case EOVERFLOW: case EROFS: case ETXTBSY: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; + break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; + break; } } return rc; diff --git a/platform/example/functions/_PDCLIB/rename.c b/platform/example/functions/_PDCLIB/rename.c index f314e4c..a37eeb3 100644 --- a/platform/example/functions/_PDCLIB/rename.c +++ b/platform/example/functions/_PDCLIB/rename.c @@ -29,6 +29,9 @@ int _PDCLIB_rename( const char * old, const char * new ) { switch ( errno ) { + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EACCES: case EFAULT: case EIO: @@ -40,10 +43,11 @@ int _PDCLIB_rename( const char * old, const char * new ) case ENOTDIR: case EPERM: case EROFS: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } return -1; @@ -57,6 +61,9 @@ int _PDCLIB_rename( const char * old, const char * new ) { switch ( errno ) { + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EACCES: case EEXIST: case EFAULT: @@ -71,10 +78,11 @@ int _PDCLIB_rename( const char * old, const char * new ) case EPERM: case EROFS: case EXDEV: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } return EOF; diff --git a/platform/example/functions/_PDCLIB/seek.c b/platform/example/functions/_PDCLIB/seek.c index 9e2d102..b28de73 100644 --- a/platform/example/functions/_PDCLIB/seek.c +++ b/platform/example/functions/_PDCLIB/seek.c @@ -27,7 +27,10 @@ _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t of /* EMPTY - OK */ break; default: - _PDCLIB_errno = _PDCLIB_EINVAL; + /* See comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ + _PDCLIB_errno = _PDCLIB_ERROR; return EOF; break; } @@ -44,10 +47,14 @@ _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t of { case EBADF: case EFAULT: - _PDCLIB_errno = _PDCLIB_EIO; + /* See comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should probably be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } return EOF; diff --git a/platform/example/functions/_PDCLIB/stdinit.c b/platform/example/functions/_PDCLIB/stdinit.c index 5550c4d..9467077 100644 --- a/platform/example/functions/_PDCLIB/stdinit.c +++ b/platform/example/functions/_PDCLIB/stdinit.c @@ -306,6 +306,12 @@ static struct _PDCLIB_ctype_t _ctype[] = { struct lconv _PDCLIB_lconv = { /* _PDCLIB_ctype */ _ctype + 1, + /* _PDCLIB_errno_texts */ + { + /* no error */ (char *)"", + /* ERANGE */ (char *)"ERANGE (Range error)", + /* EDOM */ (char *)"EDOM (Domain error)" + }, /* decimal_point */ (char *)".", /* thousands_sep */ (char *)"", /* grouping */ (char *)"", diff --git a/platform/example/functions/stdio/remove.c b/platform/example/functions/stdio/remove.c index 8bf3040..389df30 100644 --- a/platform/example/functions/stdio/remove.c +++ b/platform/example/functions/stdio/remove.c @@ -37,9 +37,8 @@ int remove( const char * pathname ) { switch ( errno ) { - /* These are the values possible on a Linux machine. Adapt the - values and their mapping to PDCLib errno values at will. (This - is an example implementation, so we keep it very simple.) + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. */ case EACCES: case EFAULT: @@ -52,10 +51,11 @@ int remove( const char * pathname ) case ENOTDIR: case EPERM: case EROFS: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } } diff --git a/platform/example/internals/_PDCLIB_config.h b/platform/example/internals/_PDCLIB_config.h index f1d1475..0059a7f 100644 --- a/platform/example/internals/_PDCLIB_config.h +++ b/platform/example/internals/_PDCLIB_config.h @@ -32,6 +32,14 @@ /* to nothing. (This is to avoid warnings with the exit functions under GCC.) */ #define _PDCLIB_NORETURN __attribute__(( noreturn )) +/* The maximum value that errno can be set to. This is used to set the size */ +/* of the array in struct lconv () holding error messages for the */ +/* strerror() and perror() functions. (If you change this value because you */ +/* are using additional errno values, you *HAVE* to provide appropriate error */ +/* messages for *ALL* locales.) */ +/* Default is 2 (0, ERANGE, EDOM). */ +#define _PDCLIB_ERRNO_MAX 3 + /* -------------------------------------------------------------------------- */ /* Integers */ /* -------------------------------------------------------------------------- */ @@ -285,3 +293,61 @@ typedef int _PDCLIB_fd_t; this capability dependent on implementation-defined behaviour (not good). */ #define _PDCLIB_UNGETCBUFSIZE 1 + +/* errno -------------------------------------------------------------------- */ + +/* These are the values that _PDCLIB_errno can be set to by the library. + + By keeping PDCLib's errno in the _PDCLIB_* namespace, the library is capable + to "translate" between errno values used by the hosting operating system and + those used and passed out by the library. + + Example: In the example platform, the remove() function uses the unlink() + system call as backend. Linux sets its errno to EISDIR if you try to unlink() + a directory, but POSIX demands EPERM. Within the remove() function, you can + catch the 'errno == EISDIR', and set '_PDCLIB_errno = _PDCLIB_EPERM'. Anyone + using PDCLib's will "see" EPERM instead of EISDIR (the _PDCLIB_* + prefix removed by mechanics). + + If you do not want that kind of translation, you might want to "match" the + values used by PDCLib with those used by the host OS, as to avoid confusion. + + The standard only defines three distinct errno values: ERANGE, EDOM, and + EILSEQ. The standard leaves it up to "the implementation" whether there are + any more beyond those three. There is some controversy as to whether errno is + such a good idea at all, so you might want to come up with a different error + reporting facility for your platform. Since errno values beyond the three + defined by the standard are not portable anyway (unless you look at POSIX), + having your own error reporting facility would not hurt anybody either. +*/ +#define _PDCLIB_ERANGE 1 +#define _PDCLIB_EDOM 2 +#define _PDCLIB_EILSEQ 3 + +/* The following is not strictly "configuration", but there is no better place + to explain it than here. + + PDCLib strives to be as generic as possible, so by default it does NOT define + any values beyond the three standard ones above, even where it would have + been prudent and convenient to do so. Any errno "caught" from the host OS, + and some internal error conditions as well, are all lumped together into the + value of '_PDCLIB_ERROR'. + + '_PDCLIB_ERROR' is STRICLY meant as a PLACEHOLDER only. + + You should NEVER ship an adaption of PDCLib still using that particular + value. You should NEVER write code that *tests* for that value. Indeed it is + not even conforming, since errno values should be defined as beginning with + an uppercase 'E', and there is no mechanics in to unmask that + particular value (for exactly that reason). + + The idea is that you scan the source of PDCLib for occurrences of this macro + and replace _PDCLIB_ERROR with whatever additional errno value you came up + with for your platform. + + If you cannot find it within you to do that, tell your clients to check for + an errno value larger than zero. That, at least, would be standard compliant + (and fully portable). +*/ +#define _PDCLIB_ERROR 4 + diff --git a/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c b/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c index ecfb968..293e6c9 100644 --- a/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c +++ b/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c @@ -40,15 +40,19 @@ int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) /* Reading error */ switch ( errno ) { + /* See comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EBADF: case EFAULT: case EINTR: case EINVAL: case EIO: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should probably be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } stream->status |= _PDCLIB_ERRORFLAG; diff --git a/platform/example_cygwin/functions/_PDCLIB/flushbuffer.c b/platform/example_cygwin/functions/_PDCLIB/flushbuffer.c index c2ac98d..e68c6c4 100644 --- a/platform/example_cygwin/functions/_PDCLIB/flushbuffer.c +++ b/platform/example_cygwin/functions/_PDCLIB/flushbuffer.c @@ -50,6 +50,10 @@ int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) /* Write error */ switch ( errno ) { + /* See <_PDCLIB_config.h>. There should be differenciated errno + handling here, possibly even a 1:1 mapping; but that is up + to the individual platform. + */ case EBADF: case EFAULT: case EFBIG: @@ -58,10 +62,11 @@ int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) case EIO: case ENOSPC: case EPIPE: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } stream->status |= _PDCLIB_ERRORFLAG; @@ -79,7 +84,10 @@ int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) return 0; } } - _PDCLIB_errno = _PDCLIB_ERETRY; + /* Number of retries exceeded. You probably want a different errno value + here. + */ + _PDCLIB_errno = _PDCLIB_ERROR; stream->status |= _PDCLIB_ERRORFLAG; /* Move unwritten remains to begin of buffer. */ stream->bufidx -= written; diff --git a/platform/example_cygwin/functions/_PDCLIB/open.c b/platform/example_cygwin/functions/_PDCLIB/open.c index 88af3c4..4e7d2b9 100644 --- a/platform/example_cygwin/functions/_PDCLIB/open.c +++ b/platform/example_cygwin/functions/_PDCLIB/open.c @@ -66,6 +66,9 @@ int _PDCLIB_open( char const * const filename, unsigned int mode ) { switch ( errno ) { + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EACCES: case EFAULT: case EINTR: @@ -82,9 +85,12 @@ int _PDCLIB_open( char const * const filename, unsigned int mode ) case EOVERFLOW: case EROFS: case ETXTBSY: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; + break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; + break; } } return rc; diff --git a/platform/example_cygwin/functions/_PDCLIB/rename.c b/platform/example_cygwin/functions/_PDCLIB/rename.c index e8e7cb1..db38afd 100644 --- a/platform/example_cygwin/functions/_PDCLIB/rename.c +++ b/platform/example_cygwin/functions/_PDCLIB/rename.c @@ -29,6 +29,9 @@ int _PDCLIB_rename( const char * old, const char * new ) { switch ( errno ) { + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EACCES: case EFAULT: case EIO: @@ -40,10 +43,11 @@ int _PDCLIB_rename( const char * old, const char * new ) case ENOTDIR: case EPERM: case EROFS: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } return -1; @@ -57,6 +61,9 @@ int _PDCLIB_rename( const char * old, const char * new ) { switch ( errno ) { + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EACCES: case EEXIST: case EFAULT: @@ -71,10 +78,11 @@ int _PDCLIB_rename( const char * old, const char * new ) case EPERM: case EROFS: case EXDEV: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } return EOF; diff --git a/platform/example_cygwin/functions/_PDCLIB/seek.c b/platform/example_cygwin/functions/_PDCLIB/seek.c index ee21f56..bc003ee 100644 --- a/platform/example_cygwin/functions/_PDCLIB/seek.c +++ b/platform/example_cygwin/functions/_PDCLIB/seek.c @@ -27,7 +27,7 @@ _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t of /* EMPTY - OK */ break; default: - _PDCLIB_errno = _PDCLIB_EINVAL; + _PDCLIB_errno = _PDCLIB_ERROR; return EOF; break; } @@ -42,12 +42,16 @@ _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t of } switch ( errno ) { + /* See comments on implementation-defined errno values in + <_PDCLIB_config.h>. + */ case EBADF: case EFAULT: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should probably be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } return EOF; diff --git a/platform/example_cygwin/functions/stdio/remove.c b/platform/example_cygwin/functions/stdio/remove.c index 0e66f4c..e27dd56 100644 --- a/platform/example_cygwin/functions/stdio/remove.c +++ b/platform/example_cygwin/functions/stdio/remove.c @@ -24,9 +24,8 @@ int remove( const char * pathname ) { switch ( errno ) { - /* These are the values possible on a Linux machine. Adapt the - values and their mapping to PDCLib errno values at will. (This - is an example implementation, so we keep it very simple.) + /* See the comments on implementation-defined errno values in + <_PDCLIB_config.h>. */ case EACCES: case EFAULT: @@ -39,10 +38,11 @@ int remove( const char * pathname ) case ENOTDIR: case EPERM: case EROFS: - _PDCLIB_errno = _PDCLIB_EIO; + _PDCLIB_errno = _PDCLIB_ERROR; break; default: - _PDCLIB_errno = _PDCLIB_EUNKNOWN; + /* This should be something like EUNKNOWN. */ + _PDCLIB_errno = _PDCLIB_ERROR; break; } }