github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/syscall/signame.c (about)

     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, 0, FlagNoScan);
    35    __builtin_memcpy (data, s, len);
    36    ret.str = data;
    37    ret.len = len;
    38    return ret;
    39  }