Imported Upstream version 2.5.1
[debian/amanda] / common-src / clock.c
index 732b4ef01b578b3b57c1a4e0ca16b53ad572851d..905c68e603a50d6048e4253089e735a1ea7f1021 100644 (file)
@@ -25,7 +25,7 @@
  *                        University of Maryland at College Park
  */
 /*
- * $Id: clock.c,v 1.5 2002/04/08 00:16:18 jrjackson Exp $
+ * $Id: clock.c,v 1.7 2006/07/27 18:12:10 martinea Exp $
  *
  * timing functions
  */
 #include "clock.h"
 
 /* local functions */
-static struct timeval timesub P((struct timeval end, struct timeval start));
-static struct timeval timeadd P((struct timeval a, struct timeval b));
+static struct timeval timesub(struct timeval end, struct timeval start);
+static struct timeval timeadd(struct timeval a, struct timeval b);
 
-times_t times_zero = {{0,0}};
+times_t times_zero;
 times_t start_time;
 static int clock_running = 0;
 
-int clock_is_running()
+int
+clock_is_running(void)
 {
     return clock_running;
 }
 
-void startclock()
+void
+startclock(void)
 {
     amanda_timezone dontcare;
 
@@ -54,7 +56,8 @@ void startclock()
     amanda_gettimeofday(&start_time.r, &dontcare);
 }
 
-times_t stopclock()
+times_t
+stopclock(void)
 {
     times_t diff;
     struct timeval end_time;
@@ -70,7 +73,8 @@ times_t stopclock()
     return diff;
 }
 
-times_t curclock()
+times_t
+curclock(void)
 {
     times_t diff;
     struct timeval end_time;
@@ -85,8 +89,10 @@ times_t curclock()
     return diff;
 }
 
-times_t timesadd(a,b)
-times_t a,b;
+times_t
+timesadd(
+    times_t    a,
+    times_t    b)
 {
     times_t sum;
 
@@ -94,8 +100,10 @@ times_t a,b;
     return sum;
 }
 
-times_t timessub(a,b)
-times_t a,b;
+times_t
+timessub(
+    times_t    a,
+    times_t    b)
 {
     times_t dif;
 
@@ -103,43 +111,50 @@ times_t a,b;
     return dif;
 }
 
-char *times_str(t)
-times_t t;
+char *
+times_str(
+    times_t    t)
 {
     static char str[10][NUM_STR_SIZE+10];
-    static int n = 0;
+    static size_t n = 0;
     char *s;
 
     /* tv_sec/tv_usec are longs on some systems */
-    snprintf(str[n], sizeof(str[n]),
-               "rtime %d.%03d", (int)t.r.tv_sec, (int)t.r.tv_usec/1000);
+    snprintf(str[n], SIZEOF(str[n]), "rtime %lu.%03lu",
+            (unsigned long)t.r.tv_sec,
+            (unsigned long)t.r.tv_usec / 1000);
     s = str[n++];
     n %= am_countof(str);
     return s;
 }
 
-char *walltime_str(t)
-times_t t;
+char *
+walltime_str(
+    times_t    t)
 {
     static char str[10][NUM_STR_SIZE+10];
-    static int n = 0;
+    static size_t n = 0;
     char *s;
 
     /* tv_sec/tv_usec are longs on some systems */
-    snprintf(str[n], sizeof(str[n]),
-               "%d.%03d", (int)t.r.tv_sec, (int)t.r.tv_usec/1000);
+    snprintf(str[n], SIZEOF(str[n]), "%lu.%03lu",
+            (unsigned long)t.r.tv_sec,
+            (unsigned long)t.r.tv_usec/1000);
     s = str[n++];
     n %= am_countof(str);
     return s;
 }
 
-static struct timeval timesub(end,start)
-struct timeval end,start;
+static struct timeval
+timesub(
+    struct timeval     end,
+    struct timeval     start)
 {
     struct timeval diff;
 
     if(end.tv_usec < start.tv_usec) { /* borrow 1 sec */
-       end.tv_sec -= 1;
+       if (end.tv_sec > 0)
+           end.tv_sec -= 1;
        end.tv_usec += 1000000;
     }
     diff.tv_usec = end.tv_usec - start.tv_usec;
@@ -147,8 +162,10 @@ struct timeval end,start;
     return diff;
 }
 
-static struct timeval timeadd(a,b)
-struct timeval a,b;
+static struct timeval
+timeadd(
+    struct timeval     a,
+    struct timeval     b)
 {
     struct timeval sum;