+{ Copyright (C) 2005 Bas Steendijk and Peter Green\r
+ For conditions of distribution and use, see copyright notice in zlib_license.txt\r
+ which is included in the package\r
+ ----------------------------------------------------------------------------- }\r
+\r
+unit ltimevalstuff;\r
+interface\r
+
+{$ifdef win32}
+ type
+ ttimeval = record
+ tv_sec : longint;
+ tv_usec : longint;
+ end;
+{$else}
+ {$ifdef ver1_0}
+ uses linux;
+ {$else}
+ uses baseunix,unix;
+ {$endif}
+{$endif}
+
+\r
+procedure tv_add(var tv:ttimeval;msec:integer);\r
+function tv_compare(const tv1,tv2:ttimeval):boolean;\r
+procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);\r
+procedure msectotimeval(var tv:ttimeval;msec:integer);\r
+
+//tv_invalidtimebig will always compare as greater than any valid timeval\r
+//unfortunately unixstuff.inc hasn't worked it's magic yet so we
+//have to ifdef this manually.\r
+const\r
+ {$ifdef ver1_0}
+ tv_invalidtimebig : ttimeval = (sec:maxlongint;usec:maxlongint);\r
+ {$else}
+ \rtv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);\r
+\r {$endif}
+implementation\r
+
+{$i unixstuff.inc}
+\r
+{add nn msec to tv}\r
+procedure tv_add(var tv:ttimeval;msec:integer);\r
+begin\r
+ inc(tv.tv_usec,msec*1000);\r
+ inc(tv.tv_sec,tv.tv_usec div 1000000);\r
+ tv.tv_usec := tv.tv_usec mod 1000000;\r
+end;\r
+\r
+{tv1 >= tv2}\r
+function tv_compare(const tv1,tv2:ttimeval):boolean;\r
+begin\r
+ if tv1.tv_sec = tv2.tv_sec then begin\r
+ result := tv1.tv_usec >= tv2.tv_usec;\r
+ end else result := tv1.tv_sec > tv2.tv_sec;\r
+end;\r
+\r
+procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);\r
+begin\r
+ dec(tv.tv_usec,tv2.tv_usec);\r
+ if tv.tv_usec < 0 then begin\r
+ inc(tv.tv_usec,1000000);\r
+ dec(tv.tv_sec)\r
+ end;\r
+ dec(tv.tv_sec,tv2.tv_sec);\r
+end;\r
+\r
+procedure msectotimeval(var tv:ttimeval;msec:integer);\r
+begin\r
+ tv.tv_sec := msec div 1000;\r
+ tv.tv_usec := (msec mod 1000)*1000;\r
+end;\r
+\r
+end.
\ No newline at end of file