1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #define __FORCE_GLIBC__
- #include <features.h>
- #include <stdio.h>
- #include <string.h>
- #include <netdb.h>
- 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 = "Unknown error";
- if ((h_errno >= 0) && (h_errno < h_nerr)) {
- p = h_errlist[h_errno];
- }
- fprintf(stderr, "%s%s%s\n", s, c, p);
- }
|