allow setting of sigar_strerror

This commit is contained in:
Doug MacEachern 2007-04-15 23:06:57 +00:00
parent 4c6a988854
commit aa4e73c437
2 changed files with 27 additions and 1 deletions

View File

@ -156,6 +156,10 @@ char *sigar_os_error_string(sigar_t *sigar, int err);
char *sigar_strerror_get(int err, char *errbuf, int buflen); char *sigar_strerror_get(int err, char *errbuf, int buflen);
void sigar_strerror_set(sigar_t *sigar, char *msg);
void sigar_strerror_printf(sigar_t *sigar, const char *format, ...);
int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo); int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo);
int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo); int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo);

View File

@ -17,6 +17,8 @@
*/ */
#include <errno.h> #include <errno.h>
#include <stdio.h>
#ifndef WIN32 #ifndef WIN32
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -196,6 +198,10 @@ SIGAR_DECLARE(char *) sigar_strerror(sigar_t *sigar, int err)
{ {
char *buf; char *buf;
if (err < 0) {
return sigar->errbuf;
}
if (err > SIGAR_OS_START_ERROR) { if (err > SIGAR_OS_START_ERROR) {
if ((buf = sigar_os_error_string(sigar, err)) != NULL) { if ((buf = sigar_os_error_string(sigar, err)) != NULL) {
return buf; return buf;
@ -249,7 +255,23 @@ char *sigar_strerror_get(int err, char *errbuf, int buflen)
return errbuf; return errbuf;
} }
#include <stdio.h> /* for sprintf */ void sigar_strerror_set(sigar_t *sigar, char *msg)
{
SIGAR_SSTRCPY(sigar->errbuf, msg);
}
#ifdef WIN32
#define vsnprintf _vsnprintf
#endif
void sigar_strerror_printf(sigar_t *sigar, const char *format, ...)
{
va_list args;
va_start(args, format);
vsnprintf(sigar->errbuf, sizeof(sigar->errbuf), format, args);
va_end(args);
}
SIGAR_DECLARE(int) sigar_uptime_string(sigar_t *sigar, SIGAR_DECLARE(int) sigar_uptime_string(sigar_t *sigar,
sigar_uptime_t *uptime, sigar_uptime_t *uptime,