Changeset 132ab5d1 in mainline for uspace/lib/c/generic/str_error.c
- Timestamp:
- 2018-01-30T03:20:45Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5a6cc679
- Parents:
- 8bfb163 (diff), 6a5d05b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str_error.c
r8bfb163 r132ab5d1 1 1 /* 2 2 * Copyright (c) 2010 Martin Decky 3 * Copyright (c) 2017 CZ.NIC, z.s.p.o. 3 4 * All rights reserved. 4 5 * … … 38 39 #include <fibril.h> 39 40 40 #define MIN_ERRNO -1741 41 #define NOERR_LEN 64 42 42 43 /* The arrays below are automatically generated from the same file that 44 * errno.h constants are generated from. Triple-include of the same list 45 * with redefinitions of __errno() macro are used to ensure that the 46 * information cannot get out of synch. This is inpired by musl libc. 47 */ 48 49 #undef __errno_entry 50 #define __errno_entry(name, num, desc) name, 51 52 static const errno_t err_num[] = { 53 #include <abi/errno.in> 54 }; 55 56 #undef __errno_entry 57 #define __errno_entry(name, num, desc) #name, 58 59 static const char* err_name[] = { 60 #include <abi/errno.in> 61 }; 62 63 #undef __errno_entry 64 #define __errno_entry(name, num, desc) "[" #name "]" desc, 65 43 66 static const char* err_desc[] = { 44 "No error", 45 "No such entry", 46 "Not enough memory", 47 "Limit exceeded", 48 "Connection refused", 49 "Forwarding error", 50 "Permission denied", 51 "Answerbox closed connection", 52 "Other party error", 53 "Entry already exists", 54 "Bad memory pointer", 55 "Not supported", 56 "Address not available", 57 "Timeout expired", 58 "Invalid value", 59 "Resource is busy", 60 "Result does not fit its size", 61 "Operation interrupted" 67 #include <abi/errno.in> 62 68 }; 63 69 64 70 static fibril_local char noerr[NOERR_LEN]; 65 71 66 const char *str_error(const int e) 72 /* Returns index corresponding to the given errno, or -1 if not found. */ 73 static int find_errno(errno_t e) 67 74 { 68 if ((e <= 0) && (e >= MIN_ERRNO)) 69 return err_desc[-e]; 70 71 /* Ad hoc descriptions of error codes interesting for USB. */ 72 // FIXME: integrate these as first-class error values 73 switch (e) { 74 case ENOFS: 75 return "No such file system type"; 76 case EBADCHECKSUM: 77 return "Bad checksum"; 78 case ESTALL: 79 return "Operation stalled"; 80 case EAGAIN: 81 return "Resource temporarily unavailable"; 82 case EEMPTY: 83 return "Resource is empty"; 84 default: 85 break; 75 /* Just a dumb linear search. 76 * There are too few entries to warrant anything smarter. 77 */ 78 79 int len = sizeof(err_num) / sizeof(errno_t); 80 81 for (int i = 0; i < len; i++) { 82 if (err_num[i] == e) { 83 return i; 84 } 86 85 } 87 86 88 snprintf(noerr, NOERR_LEN, "Unkown error code %d", e); 87 return -1; 88 } 89 90 const char *str_error_name(errno_t e) 91 { 92 int i = find_errno(e); 93 94 if (i >= 0) { 95 return err_name[i]; 96 } 97 98 snprintf(noerr, NOERR_LEN, "(%d)", (int)e); 99 return noerr; 100 } 101 102 const char *str_error(errno_t e) 103 { 104 int i = find_errno(e); 105 106 if (i >= 0) { 107 return err_desc[i]; 108 } 109 110 snprintf(noerr, NOERR_LEN, "Unknown error code (%d)", (int)e); 89 111 return noerr; 90 112 }
Note:
See TracChangeset
for help on using the changeset viewer.