* glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so * provide a wrapper. */
| 106 | * provide a wrapper. |
| 107 | */ |
| 108 | int |
| 109 | buferror(int err, char *buf, size_t buflen) { |
| 110 | #ifdef _WIN32 |
| 111 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, |
| 112 | (LPSTR)buf, (DWORD)buflen, NULL); |
| 113 | return 0; |
| 114 | #elif defined(__GLIBC__) && defined(_GNU_SOURCE) |
| 115 | char *b = strerror_r(err, buf, buflen); |
| 116 | if (b != buf) { |
| 117 | strncpy(buf, b, buflen); |
| 118 | buf[buflen-1] = '\0'; |
| 119 | } |
| 120 | return 0; |
| 121 | #else |
| 122 | return strerror_r(err, buf, buflen); |
| 123 | #endif |
| 124 | } |
| 125 | |
| 126 | uintmax_t |
| 127 | malloc_strtoumax(const char *restrict nptr, char **restrict endptr, int base) { |
no outgoing calls