gonzui


Format: Advanced Search

t2ex/t2ex_source/lib/libc/src/stdlib/strercd_r.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2012/12/12.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: /*
   15:  * This software package is available for use, modification, 
   16:  * and redistribution in accordance with the terms of the attached 
   17:  * T-License 2.x.
   18:  * If you want to redistribute the source code, you need to attach 
   19:  * the T-License 2.x document.
   20:  * There's no obligation to publish the content, and no obligation 
   21:  * to disclose it to the TRON Forum if you have modified the 
   22:  * software package.
   23:  * You can also distribute the modified source code. In this case, 
   24:  * please register the modification to T-Kernel traceability service.
   25:  * People can know the history of modifications by the service, 
   26:  * and can be sure that the version you have inherited some 
   27:  * modification of a particular version or not.
   28:  *
   29:  *    http://trace.tron.org/tk/?lang=en
   30:  *    http://trace.tron.org/tk/?lang=ja
   31:  *
   32:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   33:  * the portion of the software that is copyrighted by Ken Sakamura or 
   34:  * the TRON Forum does not infringe the copyrights of a third party.
   35:  * However, it does not make any warranty other than this.
   36:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   37:  * responsible for any consequences or damages caused directly or
   38:  * indirectly by the use of this software package.
   39:  *
   40:  * The source codes in bsd_source.tar.gz in this software package are 
   41:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   42:  * They need to be changed or redistributed according to the 
   43:  * representation of each source header.
   44:  */
   45: 
   46: /*
   47:  *      @(#)strercd_r.c
   48:  *
   49:  */
   50: 
   51: #include <basic.h>
   52: #include <string.h>
   53: #include <errno.h>
   54: #include <tk/errno.h>
   55: 
   56: LOCAL   const struct      {
   57:         int    mer;
   58:         const char     *msg;
   59: } e_tbl[] = {
   60:         {MERCD(E_OK), "E_OK: Completed successfully"},
   61:         {MERCD(E_SYS), "E_SYS: System error"},
   62:         {MERCD(E_NOCOP), "E_NOCOP: Coprocessor disable"},
   63:         {MERCD(E_NOSPT), "E_NOSPT: Unsupported function"},
   64:         {MERCD(E_RSFN), "E_RSFN: Reserved function code number"},
   65:         {MERCD(E_RSATR), "E_RSATR: Reserved attribute"},
   66:         {MERCD(E_PAR), "E_PAR: Parameter error"},
   67:         {MERCD(E_ID), "E_ID: Incorrect ID number"},
   68:         {MERCD(E_CTX), "E_CTX: Context error"},
   69:         {MERCD(E_MACV), "E_MACV: Inaccessible memory/access violation"},
   70:         {MERCD(E_OACV), "E_OACV: Object access violation"},
   71:         {MERCD(E_ILUSE), "E_ILUSE: Incorrect system call use"},
   72:         {MERCD(E_NOMEM), "E_NOMEM: Insufficient memory"},
   73:         {MERCD(E_LIMIT), "E_LIMIT: Exceed system limits"},
   74:         {MERCD(E_OBJ), "E_OBJ: Incorrect object state"},
   75:         {MERCD(E_NOEXS), "E_NOEXS: Object does not exist"},
   76:         {MERCD(E_QOVR), "E_QOVR: Queuing overflow"},
   77:         {MERCD(E_RLWAI), "E_RLWAI: Forcibly release wait state"},
   78:         {MERCD(E_TMOUT), "E_TMOUT: Polling fail/time out"},
   79:         {MERCD(E_DLT), "E_DLT: Waited object was deleted"},
   80:         {MERCD(E_DISWAI), "E_DISWAI: Release wait caused by wait disable"},
   81:         {MERCD(E_IO), "E_IO: Output/input error"},
   82:         {MERCD(E_NOMDA), "E_NOMDA: No media"},
   83:         {MERCD(E_BUSY), "E_BUSY: Busy state"},
   84:         {MERCD(E_ABORT), "E_ABORT: Aborted"},
   85:         {MERCD(E_RONLY), "E_RONLY: Write protected"},
   86: };
   87: 
   88: LOCAL   const struct      {
   89:         int    ser;
   90:         const char     *msg;
   91: } ex_tbl[] = {
   92:         {EPERM, "EX_PERM: Operation not permitted"},
   93:         {ENOENT, "EX_NOENT: No such file or directory"},
   94:         {ESRCH, "EX_SRCH: No such process"},
   95:         {EINTR, "EX_INTR: Interrupted system call"},
   96:         {EIO, "EX_IO: Input/output error"},
   97:         {ENXIO, "EX_NXIO: Device not configured"},
   98:         {E2BIG, "EX_2BIG: Argument list too long"},
   99:         {ENOEXEC, "EX_NOEXEC: Exec format error"},
  100:         {EBADF, "EX_BADF: Bad file descriptor"},
  101:         {ECHILD, "EX_CHILD: No child processes"},
  102:         {EDEADLK, "EX_DEADLK: Resource deadlock avoided"},
  103:         {ENOMEM, "EX_NOMEM: Cannot allocate memory"},
  104:         {EACCES, "EX_ACCES: Permission denied"},
  105:         {EFAULT, "EX_FAULT: Bad address"},
  106:         {EBUSY, "EX_BUSY: Device busy"},
  107:         {EEXIST, "EX_EXIST: File exists"},
  108:         {EXDEV, "EX_XDEV: Cross-device link"},
  109:         {ENODEV, "EX_NODEV: Operation not supported by device"},
  110:         {ENOTDIR, "EX_NOTDIR: Not a directory"},
  111:         {EISDIR, "EX_ISDIR: Is a directory"},
  112:         {EINVAL, "EX_INVAL: Invalid argument"},
  113:         {ENFILE, "EX_NFILE: Too many open files in system"},
  114:         {EMFILE, "EX_MFILE: Too many open files"},
  115:         {ENOTTY, "EX_NOTTY: Inappropriate ioctl for device"},
  116:         {EFBIG, "EX_FBIG: File too large"},
  117:         {ENOSPC, "EX_NOSPC: No space left on device"},
  118:         {ESPIPE, "EX_SPIPE: Illegal seek"},
  119:         {EROFS, "EX_ROFS: Read-only file system"},
  120:         {EMLINK, "EX_MLINK: Too many links"},
  121:         {EPIPE, "EX_PIPE: Broken pipe"},
  122:         {EDOM, "EX_DOM: Numerical argument out of domain"},
  123:         {ERANGE, "EX_RANGE: Result too large"},
  124:         {EAGAIN, "EX_AGAIN: Resource temporarily unavailable"},
  125:         {EINPROGRESS, "EX_INPROGRESS: Operation now in progress"},
  126:         {EALREADY, "EX_ALREADY: Operation already in progress"},
  127:         {ENOTSOCK, "EX_NOTSOCK: Socket operation on non-socket"},
  128:         {EDESTADDRREQ, "EX_DESTADDRREQ: Destination address required"},
  129:         {EMSGSIZE, "EX_MSGSIZE: Message too long"},
  130:         {EPROTOTYPE, "EX_PROTOTYPE: Protocol wrong type for socket"},
  131:         {ENOPROTOOPT, "EX_NOPROTOOPT: Protocol not available"},
  132:         {EPROTONOSUPPORT, "EX_PROTONOSUPPORT: Protocol not supported"},
  133:         {ESOCKTNOSUPPORT, "EX_SOCKTNOSUPPORT: Socket type not supported"},
  134:         {EOPNOTSUPP, "EX_OPNOTSUPP: Operation not supported"},
  135:         {EPFNOSUPPORT, "EX_PFNOSUPPORT: Protocol family not supported"},
  136:         {EADDRINUSE, "EX_ADDRINUSE: Address already in use"},
  137:         {EADDRNOTAVAIL, "EX_ADDRNOTAVAIL: Can't assign requested address"},
  138:         {ENETDOWN, "EX_NETDOWN: Network is down"},
  139:         {ENETUNREACH, "EX_NETUNREACH: Network is unreachable"},
  140:         {ENETRESET, "EX_NETRESET: Network dropped connection on reset"},
  141:         {ECONNABORTED, "EX_CONNABORTED: Software caused connection abort"},
  142:         {ECONNRESET, "EX_CONNRESET: Connection reset by peer"},
  143:         {ENOBUFS, "EX_NOBUFS: No buffer space available"},
  144:         {EISCONN, "EX_ISCONN: Socket is already connected"},
  145:         {ENOTCONN, "EX_NOTCONN: Socket is not connected"},
  146:         {ESHUTDOWN, "EX_SHUTDOWN: Can't send after socket shutdown"},
  147:         {ETIMEDOUT, "EX_TIMEDOUT: Operation timed out"},
  148:         {ECONNREFUSED, "EX_CONNREFUSED: Connection refused"},
  149:         {ELOOP, "EX_LOOP: Too many levels of symbolic links"},
  150:         {ENAMETOOLONG, "EX_NAMETOOLONG: File name too long"},
  151:         {EHOSTDOWN, "EX_HOSTDOWN: Host is down"},
  152:         {EHOSTUNREACH, "EX_HOSTUNREACH: No route to host"},
  153:         {ENOTEMPTY, "EX_NOTEMPTY: Directory not empty"},
  154:         {EDQUOT, "EX_DQUOT: Disk quota exceeded"},
  155:         {ENOLCK, "EX_NOLCK: No locks available"},
  156:         {ENOSYS, "EX_NOSYS: Function not implemented"},
  157:         {EFTYPE, "EX_FTYPE: Inappropriate file type or format"},
  158:         {EILSEQ, "EX_ILSEQ: Illegal byte sequence"},
  159:         {ENOTSUP, "EX_NOTSUP: Not supported"},
  160: };
  161: 
  162: EXPORT  int      strercd_r(ER er, char *buf, size_t buflen)
  163: {
  164:         int    i, n, mer, ser;
  165:         const char     *p;
  166: 
  167:         p = NULL;
  168:         mer = MERCD(er);
  169:         if (mer != EC_ERRNO) {
  170:                 for (i = 0; i < (int)(sizeof(e_tbl) / sizeof(*e_tbl)); i++) {
  171:                         if (e_tbl[i].mer == mer) {
  172:                                 p = e_tbl[i].msg;
  173:                                 break;
  174:                         }
  175:                 }
  176:         } else {
  177:                 ser = SERCD(er);
  178:                 for (i = 0; i < (int)(sizeof(ex_tbl) / sizeof(*ex_tbl)); i++) {
  179:                         if (ex_tbl[i].ser == ser) {
  180:                                 p = ex_tbl[i].msg;
  181:                                 break;
  182:                         }
  183:                 }
  184:         }
  185: 
  186:         if (p != NULL) {
  187:                 n = strlen( p );
  188:                 if (n + 1 > (int)buflen) goto e2;
  189:                 strcpy( buf, p );
  190:                 return 0;
  191:         }
  192: 
  193:         return EINVAL;
  194: e2:     return ERANGE;
  195: }