jit: Fix Darwin bootstrap after r15-1699.
[official-gcc.git] / libgo / go / syscall / signame.c
blobe2e77cb3bd07f79764bc0554b06e903ca71f76e2
1 /* signame.c -- get the name of a signal
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. */
7 #include <string.h>
9 #include "runtime.h"
10 #include "arch.h"
11 #include "malloc.h"
13 String Signame (intgo sig) __asm__ (GOSYM_PREFIX "syscall.Signame");
15 String
16 Signame (intgo sig)
18 const char* s = NULL;
19 char buf[100];
20 size_t len;
21 byte *data;
22 String ret;
24 #if defined(HAVE_STRSIGNAL)
25 s = strsignal (sig);
26 #endif
28 if (s == NULL)
30 snprintf(buf, sizeof buf, "signal %ld", (long) sig);
31 s = buf;
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;