aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/signal-safe.cpp
blob: 05ca9c659cd9603d63fd6a5824b9355d46ad7c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "signal-safe.hpp"

#ifndef __GLIBC__
#include <signal.h>
#endif
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

extern char** environ;

char const*   sig_getenv(char const* name) {
    int len = strlen(name);
    for (char** var = environ; *var != NULL; var++) {
        if (strncmp(*var, name, len) == 0 && (*var)[len] == '=') {
            return (*var) + len + 1;
        }
    }
    return NULL;
}

char const* sig_strsignal(int sig) {
#ifdef __GLIBC__
    return sigabbrev_np(sig);
#elif defined(__DragonFly__) || defined(__FreeBSD__)
    return sys_signame[sig];
#else
    return "unknown";
#endif
}