/*------------------------------------------------------------------------- * Filename: strerror.c * Version: $Id: strerror.c,v 1.2 1999/05/02 20:26:27 erik Exp $ * Copyright: Copyright (C) 1999, Erik Mouw * Author: Erik Mouw * Description: strerror() replacement function for brain damaged OSes * Created at: Sat May 1 13:36:40 1999 * Modified by: Erik Mouw * Modified at: Sun May 2 16:49:33 1999 *-----------------------------------------------------------------------*/ /* * This will be compiled if your system misses the strerror() function. * * * strerror.c, Copyright (C) 1999, Erik Mouw * * Email: * J.A.K.Mouw@its.tudelft.nl * * Snail mail: * J.A.K. Mouw * Information and Communication Theory Group * Department of Electrical Engineering * Faculty of Information Technology and Systems * Delft University of Technology * P.O. Box 5031 * 2600 GA Delft * The Netherlands * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software (the "Software"), to deal in the * Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of Erik Mouw shall not * be used in advertising or otherwise to promote the sale, use or * other dealings in this Software without prior written authorization * from Erik Mouw. * * * strerror - return string describing error code * * The strerror() function normally returns a string describing the * error code passed in the argument errnum. The string can only be * used until the next call to strerror(). * * This version of strerror only knows about a couple of error numbers, * because error numbers are rather system dependent. * */ #ident "$Id: strerror.c,v 1.2 1999/05/02 20:26:27 erik Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #if STDC_HEADERS # include #else # ifdef HAVE_MALLOC_H # include # else # ifndef NULL # define NULL ((void *)0) # endif # endif #endif #include typedef struct { int number; char *string; } error_struct; static error_struct errors[] = { /* from Linux asm-i386/errno.h : */ #ifdef EPERM {EPERM, "operation not permitted"}, #endif #ifdef ENOENT {ENOENT, "no such file or directory"}, #endif #ifdef ESRCH {ESRCH, "no such process"}, #endif #ifdef EINTR {EINTR, "interrupted system call"}, #endif #ifdef EIO {EIO, "I/O error"}, #endif #ifdef ENXIO {ENXIO, "no such device or address"}, #endif #ifdef E2BIG {E2BIG, "argument list too long"}, #endif #ifdef ENOEXEC {ENOEXEC, "exec format error"}, #endif #ifdef EBADF {EBADF, "bad file descriptor"}, #endif #ifdef ECHILD {ECHILD, "no child processes"}, #endif #ifdef EAGAIN {EAGAIN, "resource temporary unavailable"}, #endif #ifdef ENOMEM {ENOMEM, "out of memory"}, #endif #ifdef EACCES {EACCES, "permission denied"}, #endif #ifdef EFAULT {EFAULT, "bad address"}, #endif #ifdef ENOTBLK {ENOTBLK, "block device required"}, #endif #ifdef EBUSY {EBUSY, "device or resource busy"}, #endif #ifdef EEXIST {EEXIST, "file exists"}, #endif #ifdef EXDEV {EXDEV, "cross-device link"}, #endif #ifdef ENODEV {ENODEV, "no such device"}, #endif #ifdef ENOTDIR {ENOTDIR, "not a directory"}, #endif #ifdef EISDIR {EISDIR, "is a directory"}, #endif #ifdef EINVAL {EINVAL, "invalid argument"}, #endif #ifdef ENFILE {ENFILE, "file table overflow"}, #endif #ifdef EMFILE {EMFILE, "too many open files"}, #endif #ifdef ENOTTY {ENOTTY, "not a typewriter"}, #endif #ifdef ETXTBSY {ETXTBSY, "text file busy"}, #endif #ifdef EFBIG {EFBIG, "file too large"}, #endif #ifdef ENOSPC {ENOSPC, "no space left on device"}, #endif #ifdef ESPIPE {ESPIPE, "illegal seek"}, #endif #ifdef EROFS {EROFS, "read-only file system"}, #endif #ifdef EMLINK {EMLINK, "too many links"}, #endif #ifdef EPIPE {EPIPE, "broken pipe"}, #endif #ifdef EDOM {EDOM, "math argument out of domain of function"}, #endif #ifdef ERANGE {ERANGE, "math result not representable"}, #endif #ifdef EDEADLK {EDEADLK, "resource deadlock avioded"}, #endif #ifdef ENAMETOOLONG {ENAMETOOLONG, "file name too long"}, #endif #ifdef ENOLCK {ENOLCK, "no record locks available"}, #endif #ifdef ENOSYS {ENOSYS, "function not implemented"}, #endif #ifdef ENOTEMPTY {ENOTEMPTY, "directory not empty"}, #endif #ifdef ELOOP {ELOOP, "too many symbolic links encountered"}, #endif #ifdef EWOULDBLOCK {EWOULDBLOCK, "operation would block"}, #endif #ifdef ENOMSG {ENOMSG, "no message of desired type"}, #endif #ifdef EIDRM {EIDRM, "identifier removed"}, #endif #ifdef ECHRNG {ECHRNG, "channel number out of range"}, #endif #ifdef EL2NSYNC {EL2NSYNC, "level 2 not synchronized"}, #endif #ifdef EL3HLT {EL3HLT, "level 3 halted"}, #endif #ifdef EL3RST {EL3RST, "level 3 reset"}, #endif #ifdef ELNRNG {ELNRNG, "link number out of range"}, #endif #ifdef EUNATCH {EUNATCH, "protocol driver not attached"}, #endif #ifdef ENOCSI {ENOCSI, "no CSI structure available"}, #endif #ifdef E2HLT {E2HLT, "level 2 halted"}, #endif #ifdef EBADE {EBADE, "invalid exchange"}, #endif #ifdef EBADR {EBADR, "invalid request descriptor"}, #endif #ifdef EXFULL {EXFULL, "exchange full"}, #endif #ifdef ENOANO {ENOANO, "no anode"}, #endif #ifdef EBADRQC {EBADRQC, "invalid request code"}, #endif #ifdef EBADSLT {EBADSLT, "invalid slot"}, #endif /* from Linux strerror manpage */ #ifdef EBADMSG {EBADMSG, "bad message"}, #endif #ifdef ECANCELED {ECANCELED, "operation canceled"}, #endif #ifdef EDOM {EDOM, "domain error"}, #endif #ifdef EINPROGRESS {EINPROGRESS, "operation in progress"}, #endif #ifdef EMSGSIZE {EMSGSIZE, "inappropriate message buffer length"}, #endif #ifdef ENOTSUP {ENOTSUP, "not supported"}, #endif #ifdef ETIMEOUT {ETIMEOUT, "operation timed out"}, #endif {0, NULL} }; static char *unknown_error = "unknown error number, check system header files"; #ifdef __cplusplus extern "C" char *strerror(int errnum) #else char *strerror(int errnum) #endif { int i; for(i = 0; errors[i].string != NULL; i++) { if((errors[i].number == errnum) || (errors[i].number == -errnum)) break; } if(errors[i].string != NULL) return(errors[i].string); else return(unknown_error); }