aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/1004-define-and-implement-herror.patch
blob: 0935dff6c8be532488c7617e48f1910376d91600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
From 2a21ef4263d853616df24cc8e4c00f5a2c2980e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Wed, 18 Dec 2013 13:24:06 +0200
Subject: [PATCH] define and implement herror

---
 include/netdb.h      |  1 +
 src/network/herror.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 src/network/herror.c

diff --git a/include/netdb.h b/include/netdb.h
index 8a7013a..2dd799b 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -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
index 0000000..25117a3
--- /dev/null
+++ b/src/network/herror.c
@@ -0,0 +1,23 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include "stdio_impl.h"
+
+void herror(const char *msg)
+{
+	FILE *f = stderr;
+	const char *errstr = hstrerror(h_errno);
+
+	FLOCK(f);
+
+	if (msg && *msg) {
+		fwrite(msg, strlen(msg), 1, f);
+		fputc(':', f);
+		fputc(' ', f);
+	}
+	fwrite(errstr, strlen(errstr), 1, f);
+	fputc('\n', f);
+
+	FUNLOCK(f);
+}
-- 
1.8.5.1