applib/dtn_errno.c
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2007 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #include <stdio.h>
       
    18 #include "dtn_errno.h"
       
    19 
       
    20 //----------------------------------------------------------------------
       
    21 char*
       
    22 dtn_strerror(int err)
       
    23 {
       
    24     switch(err) {
       
    25     case DTN_SUCCESS: 	return "success";
       
    26     case DTN_EINVAL: 	return "invalid argument";
       
    27     case DTN_EXDR: 	return "error in xdr routines";
       
    28     case DTN_ECOMM: 	return "error in ipc communication";
       
    29     case DTN_ECONNECT: 	return "error connecting to server";
       
    30     case DTN_ETIMEOUT: 	return "operation timed out";
       
    31     case DTN_ESIZE: 	return "payload too large";
       
    32     case DTN_ENOTFOUND: return "not found";
       
    33     case DTN_EINTERNAL: return "internal error";
       
    34     case DTN_EINPOLL:   return "illegal operation called after dtn_poll";
       
    35     case DTN_EBUSY:     return "registration already in use";
       
    36     case DTN_EVERSION:  return "ipc version mismatch";
       
    37     case DTN_EMSGTYPE:  return "unknown ipc message type";
       
    38     case DTN_ENOSPACE:	return "no storage space";
       
    39     case -1:            return "(invalid error code -1)";
       
    40     }
       
    41 
       
    42     // there's a small race condition here in case there are two
       
    43     // simultaneous calls that will clobber the same buffer, but this
       
    44     // should be rare and the worst that happens is that the output
       
    45     // string is garbled
       
    46     static char buf[128];
       
    47     snprintf(buf, sizeof(buf), "(unknown error %d)", err);
       
    48     return buf;
       
    49 }
       
    50