From aa4e73c437dc0294730e8607e7d0e65009b4c570 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 15 Apr 2007 23:06:57 +0000 Subject: [PATCH] allow setting of sigar_strerror --- include/sigar_private.h | 4 ++++ src/sigar.c | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/sigar_private.h b/include/sigar_private.h index de037d6c..8c21abbb 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -156,6 +156,10 @@ char *sigar_os_error_string(sigar_t *sigar, int err); 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_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo); diff --git a/src/sigar.c b/src/sigar.c index 6c76c411..98680382 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -17,6 +17,8 @@ */ #include +#include + #ifndef WIN32 #include #include @@ -196,6 +198,10 @@ 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; @@ -249,7 +255,23 @@ char *sigar_strerror_get(int err, char *errbuf, int buflen) return errbuf; } -#include /* 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_uptime_t *uptime,