From: Karl DeBisschop Date: Wed, 16 Oct 2002 04:56:19 +0000 (+0000) Subject: start support for gettimeofday and tv_usec X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6cbf1dd4a321ced6dffa5ca590692d283731f987;p=nagiosplug.git start support for gettimeofday and tv_usec git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@116 f882894a-f735-0410-b71e-b25c423dba1c --- diff --git a/plugins/utils.c b/plugins/utils.c index d97ad48..6e52dab 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -316,6 +316,19 @@ is_option (char *str) +double +delta_time (struct timeval *tv) +{ + struct timeval *pt; + struct timezone *tz; + + gettimeofday (pt, tz); + + return (pt->tv_sec - tv->tv_sec + (pt->tv_usec - tv->tv_usec) / 1000000); +} + + + void strip (char *buffer) diff --git a/plugins/utils.h.in b/plugins/utils.h.in index 46b152a..e910c41 100644 --- a/plugins/utils.h.in +++ b/plugins/utils.h.in @@ -45,13 +45,31 @@ int is_percentage (char *); int is_option (char *); +/* generalized timer that will do milliseconds if available */ +#ifndef HAVE_GETTIMEOFDAY +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* microseconds */ +}; + +struct timezone { + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +#define gettimeofday (tvp,tz) {\ + tvp->tv_usec=0;\ + tvp->tv_sec=(long)time();\ +} +#endif + /* Handle strings safely */ void strip (char *buffer); char *strscpy (char *dest, char *src); char *strscat (char *dest, char *src); char *strnl (char *str); -char *ssprintf (char *str, const char *fmt, ...); +char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */ char *strpcpy (char *dest, const char *src, const char *str); char *strpcat (char *dest, const char *src, const char *str); @@ -61,15 +79,15 @@ int max_state(int, int); #define max(a,b) ((a)>(b))?(a):(b) #define usage(msg) {\ - printf(msg);\ - print_usage();\ -exit(STATE_UNKNOWN);\ + printf(msg);\ + print_usage();\ + exit(STATE_UNKNOWN);\ } #define usage2(msg,arg) {\ - printf("%s: %s - %s\n",PROGNAME,msg,arg);\ - print_usage();\ - exit(STATE_UNKNOWN);\ + printf("%s: %s - %s\n",PROGNAME,msg,arg);\ + print_usage();\ + exit(STATE_UNKNOWN);\ } #define state_text(a) \ @@ -94,3 +112,4 @@ exit(STATE_UNKNOWN);\ {"warning",required_argument,0,'w'},\ {"hostname",required_argument,0,'H'},\ {"file",required_argument,0,'F'} +