diff options
Diffstat (limited to 'src/utils.cc')
| -rw-r--r-- | src/utils.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utils.cc b/src/utils.cc index 3937923..e7d8acd 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -1,5 +1,6 @@ #include "common.hh" +#include <signal.h> #include <sys/stat.h> static TErrorFunction *ErrorFunction; @@ -95,6 +96,46 @@ bool FileExists(const char *FileName){ return Result; } +#if !defined(_GNU_SOURCE) || (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 32)) +# if defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE) +static const char *sigdescr_np(int SigNr){ + const char *Description = NULL; + if(SigNr >= 0 && SigNr < NSIG){ + Description = sys_siglist[SigNr]; + } + return Description; +} + +static const char *strerrordesc_np(int ErrCode){ + const char *Description = NULL; + if(ErrCode >= 0 && ErrCode < sys_nerr){ + Description = sys_errlist[ErrCode]; + } + return Description; +} +# else // defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE) +#warning "Current LIBC/GLIBC version doesn't expose error/signal description tables." +static const char *sigdescr_np(int SigNr){ return "No signal description"; } +static const char *strerrordesc_np(int ErrCode){ return "No error description"; } +# endif // defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE) +#endif //!defined(_GNU_SOURCE) || (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 32)) + +const char *GetSignalDescription(int SigNr){ + const char *Description = sigdescr_np(SigNr); + if(Description == NULL){ + Description = "Invalid signal"; + } + return Description; +} + +const char *GetErrorDescription(int ErrCode){ + const char *Description = strerrordesc_np(ErrCode); + if(Description == NULL){ + Description = "Invalid error"; + } + return Description; +} + // String Utility // ============================================================================= bool isSpace(int c){ |
