1 #define STRERROR_OVERRIDE_IMPL 1
2 #include "strerror_override.h"
5 * Override strerror() to get consistent output across platforms.
10 const char *errno_str;
12 #define STRINGIFY(x) #x
13 #define ENTRY(x) {x, &STRINGIFY(undef_ ## x)[6]}
56 // Enabled during tests
57 int _json_c_strerror_enable = 0;
59 #define PREFIX "ERRNO="
60 static char errno_buf[128] = PREFIX;
61 char *_json_c_strerror(int errno_in)
67 if (!_json_c_strerror_enable)
68 return strerror(errno_in);
70 // Avoid standard functions, so we don't need to include any
71 // headers, or guess at signatures.
73 for (ii = 0; errno_list[ii].errno_str != (char *)0; ii++)
75 const char *errno_str = errno_list[ii].errno_str;
76 if (errno_list[ii].errno_value != errno_in)
79 for (start_idx = sizeof(PREFIX) - 1, jj = 0; errno_str[jj] != '\0'; jj++, start_idx++)
81 errno_buf[start_idx] = errno_str[jj];
83 errno_buf[start_idx] = '\0';
87 // It's not one of the known errno values, return the numeric value.
88 for (ii = 0; errno_in > 10; errno_in /= 10, ii++)
90 digbuf[ii] = "0123456789"[(errno_in % 10)];
92 digbuf[ii] = "0123456789"[(errno_in % 10)];
95 for (start_idx = sizeof(PREFIX) - 1 ; ii >= 0; ii--, start_idx++)
97 errno_buf[start_idx] = digbuf[ii];