| 1 |
/* signame.c -- get the name of a signal |
| 2 |
|
| 3 |
Copyright 2012 The Go Authors. All rights reserved. |
| 4 |
Use of this source code is governed by a BSD-style |
| 5 |
license that can be found in the LICENSE file. */ |
| 6 |
|
| 7 |
#include <string.h> |
| 8 |
|
| 9 |
#include "runtime.h" |
| 10 |
#include "arch.h" |
| 11 |
#include "malloc.h" |
| 12 |
|
| 13 |
String Signame (intgo sig) __asm__ (GOSYM_PREFIX "syscall.Signame"); |
| 14 |
|
| 15 |
String |
| 16 |
Signame (intgo sig) |
| 17 |
{ |
| 18 |
const char* s = NULL; |
| 19 |
char buf[100]; |
| 20 |
size_t len; |
| 21 |
byte *data; |
| 22 |
String ret; |
| 23 |
|
| 24 |
#if defined(HAVE_STRSIGNAL) |
| 25 |
s = strsignal (sig); |
| 26 |
#endif |
| 27 |
|
| 28 |
if (s == NULL) |
| 29 |
{ |
| 30 |
snprintf(buf, sizeof buf, "signal %ld", (long) sig); |
| 31 |
s = buf; |
| 32 |
} |
| 33 |
len = __builtin_strlen (s); |
| 34 |
data = runtime_mallocgc (len, nil, false); |
| 35 |
__builtin_memcpy (data, s, len); |
| 36 |
// lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 37 |
if ('A' <= data[0] && data[0] <= 'Z' && 'a' <= data[1] && data[1] <= 'z') |
| 38 |
data[0] += 'a' - 'A'; |
| 39 |
ret.str = data; |
| 40 |
ret.len = len; |
| 41 |
return ret; |
| 42 |
} |