Author: vlendec
Date: 2005-08-02 23:24:50 +0000 (Tue, 02 Aug 2005)
New Revision: 8960

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8960

Log:
Some more timeval routines from Samba4
Modified:
   trunk/source/lib/time.c


Changeset:
Modified: trunk/source/lib/time.c
===================================================================
--- trunk/source/lib/time.c     2005-08-02 23:24:32 UTC (rev 8959)
+++ trunk/source/lib/time.c     2005-08-02 23:24:50 UTC (rev 8960)
@@ -853,6 +853,15 @@
 }
 
 /*
+  return a timeval secs/usecs into the future
+*/
+struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs)
+{
+       struct timeval tv = timeval_current();
+       return timeval_add(&tv, secs, usecs);
+}
+
+/*
   compare two timeval structures. 
   Return -1 if tv1 < tv2
   Return 0 if tv1 == tv2
@@ -889,6 +898,30 @@
        return t;
 }
 
+/*
+  return the lesser of two timevals
+*/
+struct timeval timeval_min(const struct timeval *tv1,
+                          const struct timeval *tv2)
+{
+       if (tv1->tv_sec < tv2->tv_sec) return *tv1;
+       if (tv1->tv_sec > tv2->tv_sec) return *tv2;
+       if (tv1->tv_usec < tv2->tv_usec) return *tv1;
+       return *tv2;
+}
+
+/*
+  return the greater of two timevals
+*/
+struct timeval timeval_max(const struct timeval *tv1,
+                          const struct timeval *tv2)
+{
+       if (tv1->tv_sec > tv2->tv_sec) return *tv1;
+       if (tv1->tv_sec < tv2->tv_sec) return *tv2;
+       if (tv1->tv_usec > tv2->tv_usec) return *tv1;
+       return *tv2;
+}
+
 /****************************************************************************
  convert ASN.1 GeneralizedTime string to unix-time
  returns 0 on failure; Currently ignores timezone. 

Reply via email to