summaryrefslogtreecommitdiff
path: root/lib/libc/string
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2017-01-12 00:35:38 +0000
committerchristos <christos@NetBSD.org>2017-01-12 00:35:38 +0000
commit0ebc515694af4baef0c25d0cd121492560080c8e (patch)
treef0d8b2233b2997383156e7658d443d913bea419b /lib/libc/string
parent763e08bc8d1dc1cda146c09f0c54d49ead950241 (diff)
Add strerror_ss_r to be used by syslog_ss
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/Makefile.inc4
-rw-r--r--lib/libc/string/strerror_ss.c65
2 files changed, 67 insertions, 2 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index 86940ff7cb8..cf7a4ca618c 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
-# $NetBSD: Makefile.inc,v 1.82 2016/10/15 14:22:00 kamil Exp $
+# $NetBSD: Makefile.inc,v 1.83 2017/01/12 00:35:38 christos Exp $
# string sources
.PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -10,7 +10,7 @@
SRCS+= bm.c stpcpy.c stpncpy.c \
strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \
- strerror.c strlcat.c strlcpy.c strnlen.c \
+ strerror.c strerror_ss.c strlcat.c strlcpy.c strnlen.c \
strmode.c strsignal.c strtok.c \
strtok_r.c strxfrm.c __strsignal.c strerror_r.c strndup.c \
stresep.c memrchr.c
diff --git a/lib/libc/string/strerror_ss.c b/lib/libc/string/strerror_ss.c
new file mode 100644
index 00000000000..405eb82b33a
--- /dev/null
+++ b/lib/libc/string/strerror_ss.c
@@ -0,0 +1,65 @@
+/* $NetBSD: strerror_ss.c,v 1.1 2017/01/12 00:35:38 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: strerror_ss.c,v 1.1 2017/01/12 00:35:38 christos Exp $");
+
+#include "namespace.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "extern.h"
+
+#ifdef __weak_alias
+__weak_alias(strerror_r_ss,_strerror_r_ss)
+#endif
+
+int
+strerror_r_ss(int num, char *buf, size_t len)
+{
+ if (num >= 0 || num < sys_nerr)
+ strlcpy(buf, sys_errlist[num], len);
+ else
+ snprintf_ss(buf, len, "Unknown error %d", num);
+ return 0;
+}
+
+#ifdef notyet
+__aconst char *
+strerror_ss(int num)
+{
+ static char buf[64];
+
+ strerror_r_ss(num, buf, sizeof(buf));
+ return buf;
+}
+#endif