summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/utils.c13
-rw-r--r--plugins/utils.h.in33
2 files changed, 39 insertions, 7 deletions
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)
316 316
317 317
318 318
319double
320delta_time (struct timeval *tv)
321{
322 struct timeval *pt;
323 struct timezone *tz;
324
325 gettimeofday (pt, tz);
326
327 return (pt->tv_sec - tv->tv_sec + (pt->tv_usec - tv->tv_usec) / 1000000);
328}
329
330
331
319 332
320void 333void
321strip (char *buffer) 334strip (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 *);
45 45
46int is_option (char *); 46int is_option (char *);
47 47
48/* generalized timer that will do milliseconds if available */
49#ifndef HAVE_GETTIMEOFDAY
50struct timeval {
51 long tv_sec; /* seconds */
52 long tv_usec; /* microseconds */
53};
54
55struct timezone {
56 int tz_minuteswest; /* minutes W of Greenwich */
57 int tz_dsttime; /* type of dst correction */
58};
59
60#define gettimeofday (tvp,tz) {\
61 tvp->tv_usec=0;\
62 tvp->tv_sec=(long)time();\
63}
64#endif
65
48/* Handle strings safely */ 66/* Handle strings safely */
49 67
50void strip (char *buffer); 68void strip (char *buffer);
51char *strscpy (char *dest, char *src); 69char *strscpy (char *dest, char *src);
52char *strscat (char *dest, char *src); 70char *strscat (char *dest, char *src);
53char *strnl (char *str); 71char *strnl (char *str);
54char *ssprintf (char *str, const char *fmt, ...); 72char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */
55char *strpcpy (char *dest, const char *src, const char *str); 73char *strpcpy (char *dest, const char *src, const char *str);
56char *strpcat (char *dest, const char *src, const char *str); 74char *strpcat (char *dest, const char *src, const char *str);
57 75
@@ -61,15 +79,15 @@ int max_state(int, int);
61#define max(a,b) ((a)>(b))?(a):(b) 79#define max(a,b) ((a)>(b))?(a):(b)
62 80
63#define usage(msg) {\ 81#define usage(msg) {\
64 printf(msg);\ 82 printf(msg);\
65 print_usage();\ 83 print_usage();\
66exit(STATE_UNKNOWN);\ 84 exit(STATE_UNKNOWN);\
67} 85}
68 86
69#define usage2(msg,arg) {\ 87#define usage2(msg,arg) {\
70 printf("%s: %s - %s\n",PROGNAME,msg,arg);\ 88 printf("%s: %s - %s\n",PROGNAME,msg,arg);\
71 print_usage();\ 89 print_usage();\
72 exit(STATE_UNKNOWN);\ 90 exit(STATE_UNKNOWN);\
73} 91}
74 92
75#define state_text(a) \ 93#define state_text(a) \
@@ -94,3 +112,4 @@ exit(STATE_UNKNOWN);\
94{"warning",required_argument,0,'w'},\ 112{"warning",required_argument,0,'w'},\
95{"hostname",required_argument,0,'H'},\ 113{"hostname",required_argument,0,'H'},\
96{"file",required_argument,0,'F'} 114{"file",required_argument,0,'F'}
115