genericopenlibs/cstdlib/LSTDIO/STRERROR.C
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * *** CAUTION!!! KEEP DOC CONSISTENT---if you change text of a message
       
    16 * ***            here, change two places:
       
    17 * ***            1) the leading doc section (alphabetized by macro)
       
    18 * ***            2) the real text inside switch(errnum)
       
    19 * FUNCTION
       
    20 * <<strerror>>---convert error number to string
       
    21 * INDEX
       
    22 * strerror
       
    23 * ANSI_SYNOPSIS
       
    24 * #include <string.h>
       
    25 * char *strerror(int <[errnum]>);
       
    26 * TRAD_SYNOPSIS
       
    27 * #include <string.h>
       
    28 * char *strerror(<[errnum]>)
       
    29 * int <[errnum]>;
       
    30 * <<strerror>> converts the error number <[errnum]> into a
       
    31 * string.  The value of <[errnum]> is usually a copy of <<errno>>.
       
    32 * If <<errnum>> is not a known error number, the result points to an
       
    33 * empty string.
       
    34 * RETURNS
       
    35 * This function returns a pointer to a string.  Your application must
       
    36 * not modify that string.
       
    37 * PORTABILITY
       
    38 * ANSI C requires <<strerror>>, but does not specify the strings used
       
    39 * for each error number.
       
    40 * Although this implementation of <<strerror>> is reentrant, ANSI C
       
    41 * declares that subsequent calls to <<strerror>> may overwrite the
       
    42 * result string; therefore portable code cannot depend on the reentrancy
       
    43 * of this subroutine.
       
    44 * <<strerror>> requires no supporting OS subroutines.
       
    45 * QUICKREF
       
    46 * strerror ansi pure
       
    47 * 
       
    48 *
       
    49 */
       
    50 
       
    51 
       
    52 
       
    53 #include <errno.h>
       
    54 #include <string.h>
       
    55 
       
    56 /**
       
    57 Get pointer to error message string.
       
    58 Returns a pointer to a string with the error message
       
    59 corresponding to the errnum error number.
       
    60 The returned pointer points to a statically allocated string. 
       
    61 Further calls to this function will overwrite its content.
       
    62 @param errnum Error number.
       
    63 */
       
    64 EXPORT_C char *
       
    65 strerror (int errnum)
       
    66 {
       
    67   char *error;
       
    68 
       
    69   switch (errnum)
       
    70     {
       
    71     case EPERM:
       
    72       error = "Not owner";
       
    73       break;
       
    74     case ENOENT:
       
    75       error = "No such file or directory";
       
    76       break;
       
    77     case ESRCH:
       
    78       error = "No such process";
       
    79       break;
       
    80     case EINTR:
       
    81       error = "Interrupted system call";
       
    82       break;
       
    83     case EIO:
       
    84       error = "I/O error";
       
    85       break;
       
    86     case ENXIO:
       
    87       error = "No such device or address";
       
    88       break;
       
    89     case E2BIG:
       
    90       error = "Arg list too long";
       
    91       break;
       
    92     case ENOEXEC:
       
    93       error = "Exec format error";
       
    94       break;
       
    95     case EBADF:
       
    96       error = "Bad file number";
       
    97       break;
       
    98     case ECHILD:
       
    99       error = "No children";
       
   100       break;
       
   101     case EAGAIN:
       
   102       error = "No more processes";
       
   103       break;
       
   104     case ENOMEM:
       
   105       error = "Not enough space";
       
   106       break;
       
   107     case EACCES:
       
   108       error = "Permission denied";
       
   109       break;
       
   110     case EFAULT:
       
   111       error = "Bad address";
       
   112       break;
       
   113     case ENOTBLK:
       
   114       error = "Block device required";
       
   115       break;
       
   116     case EBUSY:
       
   117       error = "Device or resource busy";
       
   118       break;
       
   119     case EEXIST:
       
   120       error = "File exists";
       
   121       break;
       
   122     case EXDEV:
       
   123       error = "Cross-device link";
       
   124       break;
       
   125     case ENODEV:
       
   126       error = "No such device";
       
   127       break;
       
   128     case ENOTDIR:
       
   129       error = "Not a directory";
       
   130       break;
       
   131     case EISDIR:
       
   132       error = "Is a directory";
       
   133       break;
       
   134     case EINVAL:
       
   135       error = "Invalid argument";
       
   136       break;
       
   137     case ENFILE:
       
   138       error = "Too many open files in system";
       
   139       break;
       
   140     case EMFILE:
       
   141       error = "Too many open files";
       
   142       break;
       
   143     case ENOTTY:
       
   144       error = "Not a character device";
       
   145       break;
       
   146     case ETXTBSY:
       
   147       error = "Text file busy";
       
   148       break;
       
   149     case EFBIG:
       
   150       error = "File too large";
       
   151       break;
       
   152     case ENOSPC:
       
   153       error = "No space left on device";
       
   154       break;
       
   155     case ESPIPE:
       
   156       error = "Illegal seek";
       
   157       break;
       
   158     case EROFS:
       
   159       error = "Read-only file system";
       
   160       break;
       
   161     case EMLINK:
       
   162       error = "Too many links";
       
   163       break;
       
   164     case EPIPE:
       
   165       error = "Broken pipe";
       
   166       break;
       
   167     case EDOM:
       
   168       error = "Math argument";
       
   169       break;
       
   170     case ERANGE:
       
   171       error = "Result too large";
       
   172       break;
       
   173     case ENOMSG:
       
   174       error = "No message of desired type";
       
   175       break;
       
   176     case EIDRM:
       
   177       error = "Identifier removed";
       
   178       break;
       
   179     case EDEADLK:
       
   180       error = "Deadlock";
       
   181       break;
       
   182     case ENOLCK:
       
   183       error = "No lock";
       
   184       break;
       
   185     case ENOTSOCK:	error = "Not a socket";				break;
       
   186     case EADDRNOTAVAIL:	error = "Remote address not available";		break;
       
   187     case EAFNOSUPPORT:	error = "Address not supported by protocol";	break;
       
   188     case EISCONN:	error = "Socket already connected";		break;
       
   189     case ECONNREFUSED:	error = "Connection refused by remote host";	break;
       
   190     case EADDRINUSE:	error = "Address already in use";		break;
       
   191     case ETIMEDOUT:	error = "Connection timed out";			break;
       
   192     case ENOSTR:
       
   193       error = "Not a stream";
       
   194       break;
       
   195     case ETIME:
       
   196       error = "Stream ioctl timeout";
       
   197       break;
       
   198     case ENOSR:
       
   199       error = "No stream resources";
       
   200       break;
       
   201     case ENONET:
       
   202       error = "Machine is not on the network";
       
   203       break;
       
   204     case ENOPKG:
       
   205       error = "No package";
       
   206       break;
       
   207     case EREMOTE:
       
   208       error = "Resource is remote";
       
   209       break;
       
   210     case ENOLINK:
       
   211       error = "Virtual circuit is gone";
       
   212       break;
       
   213     case EADV:
       
   214       error = "Advertise error";
       
   215       break;
       
   216     case ESRMNT:
       
   217       error = "Srmount error";
       
   218       break;
       
   219     case ECOMM:
       
   220       error = "Communication error";
       
   221       break;
       
   222     case EPROTO:
       
   223       error = "Protocol error";
       
   224       break;
       
   225     case EMULTIHOP:
       
   226       error = "Multihop attempted";
       
   227       break;
       
   228     case EBADMSG:
       
   229       error = "Bad message";
       
   230       break;
       
   231     case ELIBACC:
       
   232       error = "Cannot access a needed shared library";
       
   233       break;
       
   234     case ELIBBAD:
       
   235       error = "Accessing a corrupted shared library";
       
   236       break;
       
   237     case ELIBSCN:
       
   238       error = ".lib section in a.out corrupted";
       
   239       break;
       
   240     case ELIBMAX:
       
   241       error = "Attempting to link in more shared libraries than system limit";
       
   242       break;
       
   243     case ELIBEXEC:
       
   244       error = "Cannot exec a shared library directly";
       
   245       break;
       
   246     case ENOSYS:
       
   247       error = "Function not implemented";
       
   248       break;
       
   249     case ENMFILE:
       
   250       error = "No more files";
       
   251       break;
       
   252     case ENOTEMPTY:
       
   253       error = "Directory not empty";
       
   254       break;
       
   255     case ENAMETOOLONG:
       
   256       error = "File or path name too long";
       
   257       break;
       
   258 	case EILSEQ:
       
   259 	  error = "invalid wide-character encoding";
       
   260       break;
       
   261 	default:
       
   262 	error = "";
       
   263       break;
       
   264     }
       
   265 
       
   266   return error;
       
   267 }