gonzui


Format: Advanced Search

t2ex/t2ex_source/lib/libc/src/stdlib/strerror_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:  *      @(#)strerror_r.c
   48:  *
   49:  */
   50: 
   51: #include <basic.h>
   52: #include <string.h>
   53: #include <errno.h>
   54: 
   55: LOCAL   const struct      {
   56:         int    er;
   57:         const  char     *msg;
   58: } er_tbl[] = {
   59:         {EPERM, "EPERM: Operation not permitted"},
   60:         {ENOENT, "ENOENT: No such file or directory"},
   61:         {ESRCH, "ESRCH: No such process"},
   62:         {EINTR, "EINTR: Interrupted system call"},
   63:         {EIO, "EIO: Input/output error"},
   64:         {ENXIO, "ENXIO: Device not configured"},
   65:         {E2BIG, "E2BIG: Argument list too long"},
   66:         {ENOEXEC, "ENOEXEC: Exec format error"},
   67:         {EBADF, "EBADF: Bad file descriptor"},
   68:         {ECHILD, "ECHILD: No child processes"},
   69:         {EDEADLK, "EDEADLK: Resource deadlock avoided"},
   70:         {ENOMEM, "ENOMEM: Cannot allocate memory"},
   71:         {EACCES, "EACCES: Permission denied"},
   72:         {EFAULT, "EFAULT: Bad address"},
   73:         {EBUSY, "EBUSY: Device busy"},
   74:         {EEXIST, "EEXIST: File exists"},
   75:         {EXDEV, "EXDEV: Cross-device link"},
   76:         {ENODEV, "ENODEV: Operation not supported by device"},
   77:         {ENOTDIR, "ENOTDIR: Not a directory"},
   78:         {EISDIR, "EISDIR: Is a directory"},
   79:         {EINVAL, "EINVAL: Invalid argument"},
   80:         {ENFILE, "ENFILE: Too many open files in system"},
   81:         {EMFILE, "EMFILE: Too many open files"},
   82:         {ENOTTY, "ENOTTY: Inappropriate ioctl for device"},
   83:         {EFBIG, "EFBIG: File too large"},
   84:         {ENOSPC, "ENOSPC: No space left on device"},
   85:         {ESPIPE, "ESPIPE: Illegal seek"},
   86:         {EROFS, "EROFS: Read-only file system"},
   87:         {EMLINK, "EMLINK: Too many links"},
   88:         {EPIPE, "EPIPE: Broken pipe"},
   89:         {EDOM, "EDOM: Numerical argument out of domain"},
   90:         {ERANGE, "ERANGE: Result too large"},
   91:         {EAGAIN, "EAGAIN: Resource temporarily unavailable"},
   92:         {EINPROGRESS, "EINPROGRESS: Operation now in progress"},
   93:         {EALREADY, "EALREADY: Operation already in progress"},
   94:         {ENOTSOCK, "ENOTSOCK: Socket operation on non-socket"},
   95:         {EDESTADDRREQ, "EDESTADDRREQ: Destination address required"},
   96:         {EMSGSIZE, "EMSGSIZE: Message too long"},
   97:         {EPROTOTYPE, "EPROTOTYPE: Protocol wrong type for socket"},
   98:         {ENOPROTOOPT, "ENOPROTOOPT: Protocol not available"},
   99:         {EPROTONOSUPPORT, "EPROTONOSUPPORT: Protocol not supported"},
  100:         {ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT: Socket type not supported"},
  101:         {EOPNOTSUPP, "EOPNOTSUPP: Operation not supported"},
  102:         {EPFNOSUPPORT, "EPFNOSUPPORT: Protocol family not supported"},
  103:         {EADDRINUSE, "EADDRINUSE: Address already in use"},
  104:         {EADDRNOTAVAIL, "EADDRNOTAVAIL: Can't assign requested address"},
  105:         {ENETDOWN, "ENETDOWN: Network is down"},
  106:         {ENETUNREACH, "ENETUNREACH: Network is unreachable"},
  107:         {ENETRESET, "ENETRESET: Network dropped connection on reset"},
  108:         {ECONNABORTED, "ECONNABORTED: Software caused connection abort"},
  109:         {ECONNRESET, "ECONNRESET: Connection reset by peer"},
  110:         {ENOBUFS, "ENOBUFS: No buffer space available"},
  111:         {EISCONN, "EISCONN: Socket is already connected"},
  112:         {ENOTCONN, "ENOTCONN: Socket is not connected"},
  113:         {ESHUTDOWN, "ESHUTDOWN: Can't send after socket shutdown"},
  114:         {ETIMEDOUT, "ETIMEDOUT: Operation timed out"},
  115:         {ECONNREFUSED, "ECONNREFUSED: Connection refused"},
  116:         {ELOOP, "ELOOP: Too many levels of symbolic links"},
  117:         {ENAMETOOLONG, "ENAMETOOLONG: File name too long"},
  118:         {EHOSTDOWN, "EHOSTDOWN: Host is down"},
  119:         {EHOSTUNREACH, "EHOSTUNREACH: No route to host"},
  120:         {ENOTEMPTY, "ENOTEMPTY: Directory not empty"},
  121:         {EDQUOT, "EDQUOT: Disk quota exceeded"},
  122:         {ENOLCK, "ENOLCK: No locks available"},
  123:         {ENOSYS, "ENOSYS: Function not implemented"},
  124:         {EFTYPE, "EFTYPE: Inappropriate file type or format"},
  125:         {EILSEQ, "EILSEQ: Illegal byte sequence"},
  126:         {ENOTSUP, "ENOTSUP: Not supported"},
  127: };
  128: 
  129: EXPORT  int      strerror_r(errno_t errnum, char *buf, size_t buflen)
  130: {
  131:         int    i, n;
  132: 
  133:         for (i = 0; i < (int)(sizeof(er_tbl) / sizeof(*er_tbl)); i++) {
  134:                 if (er_tbl[i].er == errnum) {
  135:                         n = strlen( er_tbl[i].msg );
  136:                         if (n + 1 > (int)buflen) goto e2;
  137:                         strcpy( buf, er_tbl[i].msg );
  138:                         return 0;
  139:                 }
  140:         }
  141: 
  142:         return EINVAL;
  143: e2:     return ERANGE;
  144: }