[klibc] Add strsignal() function

The function strsignal() is generically useful; don't limit its
implementation to dash.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/klibc/Kbuild b/klibc/Kbuild
index 75847b6..6741a1c 100644
--- a/klibc/Kbuild
+++ b/klibc/Kbuild
@@ -29,7 +29,7 @@
 	  brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
 	  memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
 	  memmove.o memchr.o memrchr.o \
-	  strcasecmp.o strncasecmp.o strndup.o strerror.o \
+	  strcasecmp.o strncasecmp.o strndup.o strerror.o strsignal.o \
 	  strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o strnlen.o \
 	  strncat.o strlcpy.o strlcat.o \
 	  strstr.o strncmp.o strncpy.o strrchr.o \
diff --git a/klibc/strsignal.c b/klibc/strsignal.c
new file mode 100644
index 0000000..731d6bf
--- /dev/null
+++ b/klibc/strsignal.c
@@ -0,0 +1,25 @@
+/*
+ * strsignal.c
+ */
+
+#include <string.h>
+#include <signal.h>
+
+char *strsignal(int sig)
+{
+	static char buf[64];
+
+	if ((unsigned)sig < _NSIG && sys_siglist[sig])
+		return sys_siglist[sig];
+
+#ifdef SIGRTMIN
+	if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
+		snprintf(buf, sizeof buf, "Real-time signal %d",
+			 sig-SIGRTMIN);
+		return buf;
+	}
+#endif
+
+	snprintf(buf, sizeof buf, "Signal %d", sig);
+	return buf;
+}