summaryrefslogtreecommitdiff
path: root/libgo/go/syscall/signame.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/syscall/signame.c')
-rw-r--r--libgo/go/syscall/signame.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libgo/go/syscall/signame.c b/libgo/go/syscall/signame.c
new file mode 100644
index 00000000000..f2ff85a9a02
--- /dev/null
+++ b/libgo/go/syscall/signame.c
@@ -0,0 +1,40 @@
+/* signame.c -- get the name of a signal
+
+ Copyright 2012 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file. */
+
+#include <string.h>
+
+#include "config.h"
+#include "runtime.h"
+#include "arch.h"
+#include "malloc.h"
+
+String Signame (int sig) asm ("libgo_syscall.syscall.Signame");
+
+String
+Signame (int sig)
+{
+ const char* s = NULL;
+ char buf[100];
+ size_t len;
+ unsigned char *data;
+ String ret;
+
+#if defined(HAVE_STRSIGNAL)
+ s = strsignal (sig);
+#endif
+
+ if (s == NULL)
+ {
+ snprintf(buf, sizeof buf, "signal %d", sig);
+ s = buf;
+ }
+ len = __builtin_strlen (s);
+ data = runtime_mallocgc (len, FlagNoPointers, 0, 0);
+ __builtin_memcpy (data, s, len);
+ ret.__data = data;
+ ret.__length = len;
+ return ret;
+}