123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #define __FORCE_GLIBC
- #include <features.h>
- #include <stdio.h>
- #include <string.h>
- #include <netdb.h>
- libc_hidden_proto(fprintf)
- static const char *error_msg = "Resolver error";
- static const char *const h_errlist[] = {
- "Error 0",
- "Unknown host",
- "Host name lookup failure",
- "Unknown server error",
- "No address associated with name",
- };
- static const int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
- void herror(const char *s)
- {
- static const char colon_space[] = ": ";
- const char *p;
- const char *c;
- c = colon_space;
- if (!s || !*s) {
- c += 2;
- }
- p = error_msg;
- if ((h_errno >= 0) && (h_errno < h_nerr)) {
- p = h_errlist[h_errno];
- }
- fprintf(stderr, "%s%s%s\n", s, c, p);
- }
- libc_hidden_proto(herror)
- libc_hidden_def(herror)
- const char *hstrerror(int err)
- {
- if (err < 0) {
- return(error_msg);
- } else if (err < h_nerr) {
- return(h_errlist[err]);
- }
- return(error_msg);
- }
|