1 /* 2 * errcode.c - convert an error code to a string 3 */ 4 5 #include "config.h" 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <string.h> 9 10 static const char *err_string[] = { 11 "", 12 "UNKNOWN", /* 1 */ 13 "EIO", /* 2 */ 14 "ENOMEM", /* 3 */ 15 "EFSBADCRC", /* 4 */ 16 "EFSCORRUPTED", /* 5 */ 17 "ENOSPC", /* 6 */ 18 "ENOKEY", /* 7 */ 19 "EROFS", /* 8 */ 20 "EFBIG", /* 9 */ 21 "EEXIST", /* 10 */ 22 "ERANGE", /* 11 */ 23 "EOVERFLOW", /* 12 */ 24 "EBUSY", /* 13 */ 25 "ENOTDIR", /* 14 */ 26 "ENOTEMPTY", /* 15 */ 27 "ESHUTDOWN", /* 16 */ 28 "EFAULT", /* 17 */ 29 }; 30 31 #define ARRAY_SIZE(array) \ 32 (sizeof(array) / sizeof(array[0])) 33 34 /* Return the name of an encoding or NULL */ 35 const char *e2p_errcode2str(int err) 36 { 37 unsigned int i; 38 static char buf[32]; 39 40 if (err < ARRAY_SIZE(err_string)) 41 return err_string[err]; 42 43 sprintf(buf, "UNKNOWN_ERRCODE_%d", err); 44 return buf; 45 } 46 47