static char *sigar_error_string(int err, char *errbuf, int buflen) { switch (err) { case SIGAR_ENOTIMPL: SIGAR_STRNCPY(errbuf, "This function has not been implemented on this platform", buflen); return errbuf; default: SIGAR_STRNCPY(errbuf, "Error string not specified yet", buflen); return errbuf; } }
char *sigar_strerror_get(int err, char *errbuf, int buflen) { #ifdef WIN32 DWORD len; #endif char *buf = NULL; strcpy(errbuf, "???"); #ifdef WIN32 len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), /* force english */ (LPTSTR)errbuf, (DWORD)buflen, NULL); #else #if defined(HAVE_STRERROR_R) && defined(HAVE_STRERROR_R_GLIBC) /* * strerror_r man page says: * "The GNU version may, but need not, use the user supplied buffer" */ buf = strerror_r(err, errbuf, buflen); #elif defined(HAVE_STRERROR_R) if (strerror_r(err, errbuf, buflen) < 0) { buf = "Unknown Error"; } #else /* strerror() is thread safe on solaris and hpux */ buf = strerror(err); #endif if (buf != NULL) { SIGAR_STRNCPY(errbuf, buf, buflen); } #endif return errbuf; }
char *sigar_strerror_get(int err, char *errbuf, int buflen) { char *buf = NULL; #ifdef WIN32 DWORD len; len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, /* default language */ (LPTSTR)errbuf, (DWORD)buflen, NULL); #else #if defined(HAVE_STRERROR_R) && defined(HAVE_STRERROR_R_GLIBC) /* * strerror_r man page says: * "The GNU version may, but need not, use the user supplied buffer" */ buf = strerror_r(err, errbuf, buflen); #elif defined(HAVE_STRERROR_R) if (strerror_r(err, errbuf, buflen) < 0) { buf = "Unknown Error"; } #else /* strerror() is thread safe on solaris and hpux */ buf = strerror(err); #endif if (buf != NULL) { SIGAR_STRNCPY(errbuf, buf, buflen); } #endif return errbuf; }
SIGAR_DECLARE(char *) sigar_strerror(sigar_t *sigar, int err) { char *buf; if (err < 0) { return sigar->errbuf; } if (err > SIGAR_OS_START_ERROR) { if ((buf = sigar_os_error_string(sigar, err)) != NULL) { return buf; } SIGAR_STRNCPY(sigar->errbuf, "Unknown OS Error", sizeof(sigar->errbuf)); /* should never happen */ //return "Unknown OS Error"; /* should never happen */ return sigar->errbuf; } if (err > SIGAR_START_ERROR) { return sigar_error_string(err, sigar->errbuf, sizeof(sigar->errbuf)); } return sigar_strerror_get(err, sigar->errbuf, sizeof(sigar->errbuf)); }