implement legacy function herror
authorRich Felker <dalias@aerifal.cx>
Fri, 20 Dec 2013 16:56:16 +0000 (11:56 -0500)
committerRich Felker <dalias@aerifal.cx>
Fri, 20 Dec 2013 16:56:16 +0000 (11:56 -0500)
based on patch by Timo Teräs; greatly simplified to use fprintf.

include/netdb.h
src/network/herror.c [new file with mode: 0644]

index 8a7013ad0126454733b394a644639aa374ab0c10..2dd799b91af6c4c054e0daf0040acc01d3ac197e 100644 (file)
@@ -134,6 +134,7 @@ int *__h_errno_location(void);
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+void herror(const char *);
 const char *hstrerror(int);
 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
 int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
diff --git a/src/network/herror.c b/src/network/herror.c
new file mode 100644 (file)
index 0000000..65f25ff
--- /dev/null
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <netdb.h>
+
+void herror(const char *msg)
+{
+       fprintf(stderr, "%s%s%s", msg?msg:"", msg?": ":"", hstrerror(h_errno));
+}