Retro68/gcc/libgo/go/syscall/signame.c

40 lines
796 B
C
Raw Normal View History

2012-03-27 23:13:14 +00:00
/* 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 "runtime.h"
#include "arch.h"
#include "malloc.h"
2014-09-21 17:33:12 +00:00
String Signame (intgo sig) __asm__ (GOSYM_PREFIX "syscall.Signame");
2012-03-27 23:13:14 +00:00
String
2014-09-21 17:33:12 +00:00
Signame (intgo sig)
2012-03-27 23:13:14 +00:00
{
const char* s = NULL;
char buf[100];
size_t len;
2014-09-21 17:33:12 +00:00
byte *data;
2012-03-27 23:13:14 +00:00
String ret;
#if defined(HAVE_STRSIGNAL)
s = strsignal (sig);
#endif
if (s == NULL)
{
2014-09-21 17:33:12 +00:00
snprintf(buf, sizeof buf, "signal %ld", (long) sig);
2012-03-27 23:13:14 +00:00
s = buf;
}
len = __builtin_strlen (s);
2014-09-21 17:33:12 +00:00
data = runtime_mallocgc (len, 0, FlagNoScan);
2012-03-27 23:13:14 +00:00
__builtin_memcpy (data, s, len);
2014-09-21 17:33:12 +00:00
ret.str = data;
ret.len = len;
2012-03-27 23:13:14 +00:00
return ret;
}