00001 #ifndef NPS_ERROR_H 00002 #define NPS_ERROR_H 00003 #include <stdio.h> /* snprintf */ 00004 #include <errno.h> 00005 #include <string.h> /* strerror */ 00006 00007 /* let's try to build an error system that does not use malloc. */ 00008 00009 #if !defined BUILDING_NPS_ERROR && !defined NPS_SMALL 00010 # define NPS_ERROR_LKG static inline 00011 #else 00012 # define NPS_ERROR_LKG 00013 #endif 00014 00015 #define NPS_ERROR_MSG_LENGTH 512 00016 00017 typedef struct { 00018 const char *const desc; 00019 } nps_domain_t; 00020 00021 typedef struct { 00022 const char * const desc; 00023 } nps_errorType_t; 00024 00025 typedef struct { 00026 nps_domain_t *domain; 00027 nps_errorType_t *errorType; 00028 char msg[NPS_ERROR_MSG_LENGTH]; 00029 } nps_error_t; 00030 00031 /* macro for setting errors */ 00032 #define NPS_ERROR_SET(e,d,t,fmt...) { \ 00033 (e)->domain = &d; \ 00034 (e)->errorType = &t; \ 00035 snprintf((e)->msg,sizeof(e->msg),fmt); \ 00036 } 00037 00038 /* when there is no message (fmt==""), nsprintf gives warning, use instead... */ 00039 #define NPS_ERROR_SET0(e,d,t) { \ 00040 (e)->domain = &d; \ 00041 (e)->errorType = &t; \ 00042 *(e)->msg = 0; \ 00043 } 00044 00045 00046 extern nps_errorType_t Nps_ENOENT; 00047 extern nps_errorType_t Nps_EIO; 00048 extern nps_errorType_t Nps_EBADF; 00049 extern nps_errorType_t Nps_ENOMEM; 00050 extern nps_errorType_t Nps_EACCES; 00051 extern nps_errorType_t Nps_EBUSY; 00052 extern nps_errorType_t Nps_EEXIST; 00053 extern nps_errorType_t Nps_ENOTDIR; 00054 extern nps_errorType_t Nps_EISDIR; 00055 extern nps_errorType_t Nps_EINVAL; 00056 extern nps_errorType_t Nps_ENVAL; 00057 extern nps_errorType_t Nps_EMVAL; 00058 extern nps_errorType_t Nps_ENOTTY; 00059 extern nps_errorType_t Nps_ETXTBSY; 00060 extern nps_errorType_t Nps_EFBIG; 00061 extern nps_errorType_t Nps_ENOSPC; 00062 extern nps_errorType_t Nps_ESPIPE; 00063 extern nps_errorType_t Nps_EROFS; 00064 extern nps_errorType_t Nps_EMLINK; 00065 extern nps_errorType_t Nps_EPIPE; 00066 extern nps_errorType_t Nps_EDOM; 00067 extern nps_errorType_t Nps_ERANGE; 00068 00069 00070 00071 00072 #undef Nps_ERROR_MSG_LENGTH 00073 #endif