| 906 | */ |
| 907 | |
| 908 | const char* my_strerror(char *buf, size_t len, int nr) |
| 909 | { |
| 910 | char *msg= NULL; |
| 911 | |
| 912 | buf[0]= '\0'; /* failsafe */ |
| 913 | |
| 914 | if (nr <= 0) |
| 915 | { |
| 916 | strmake(buf, (nr == 0 ? |
| 917 | "Internal error/check (Not system error)" : |
| 918 | "Internal error < 0 (Not system error)"), |
| 919 | len-1); |
| 920 | return buf; |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | These (handler-) error messages are shared by perror, as required |
| 925 | by the principle of least surprise. |
| 926 | */ |
| 927 | if ((nr >= HA_ERR_FIRST) && (nr <= HA_ERR_LAST)) |
| 928 | { |
| 929 | msg= (char *) handler_error_messages[nr - HA_ERR_FIRST]; |
| 930 | strmake(buf, msg, len - 1); |
| 931 | } |
| 932 | else |
| 933 | { |
| 934 | /* |
| 935 | On Windows, do things the Windows way. On a system that supports both |
| 936 | the GNU and the XSI variant, use whichever was configured (GNU); if |
| 937 | this choice is not advertised, use the default (POSIX/XSI). Testing |
| 938 | for __GNUC__ is not sufficient to determine whether this choice exists. |
| 939 | */ |
| 940 | #if defined(_WIN32) |
| 941 | strerror_s(buf, len, nr); |
| 942 | #elif ((defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE >= 200112L)) || \ |
| 943 | (defined _XOPEN_SOURCE && (_XOPEN_SOURCE >= 600))) && \ |
| 944 | ! defined _GNU_SOURCE |
| 945 | strerror_r(nr, buf, len); /* I can build with or without GNU */ |
| 946 | #elif defined(__GLIBC__) && defined (_GNU_SOURCE) |
| 947 | char *r= strerror_r(nr, buf, len); |
| 948 | if (r != buf) /* Want to help, GNU? */ |
| 949 | strmake(buf, r, len - 1); /* Then don't. */ |
| 950 | #else |
| 951 | strerror_r(nr, buf, len); |
| 952 | #endif |
| 953 | |
| 954 | #ifdef __APPLE__ |
| 955 | delete_colon_char(buf); |
| 956 | #endif |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | strerror() return values are implementation-dependent, so let's |
| 961 | be pragmatic. |
| 962 | */ |
| 963 | if (!buf[0]) |
| 964 | strmake(buf, "unknown error", len - 1); |
| 965 | return buf; |
no test coverage detected