2024-04-27 18:38:48 +02:00
|
|
|
#include "signal-safe.hpp"
|
|
|
|
|
|
|
|
#ifndef __GLIBC__
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2024-12-07 18:51:18 +01:00
|
|
|
#include <cstring>
|
2024-04-27 18:38:48 +02:00
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
char const* sigGetenv(char const* name) {
|
|
|
|
const size_t len = strlen(name);
|
|
|
|
for (char** var = environ; *var != nullptr; var++) {
|
2024-04-27 18:38:48 +02:00
|
|
|
if (strncmp(*var, name, len) == 0 && (*var)[len] == '=') {
|
|
|
|
return (*var) + len + 1;
|
|
|
|
}
|
|
|
|
}
|
2024-12-07 18:51:18 +01:00
|
|
|
return nullptr;
|
2024-04-27 18:38:48 +02:00
|
|
|
}
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
char const* sigStrsignal(int sig) {
|
2024-04-27 18:38:48 +02:00
|
|
|
#ifdef __GLIBC__
|
|
|
|
return sigabbrev_np(sig);
|
|
|
|
#elif defined(__DragonFly__) || defined(__FreeBSD__)
|
|
|
|
return sys_signame[sig];
|
|
|
|
#else
|
|
|
|
return "unknown";
|
|
|
|
#endif
|
|
|
|
}
|