/[lcore]/trunk/ltimevalstuff.pas
ViewVC logotype

Contents of /trunk/ltimevalstuff.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (show annotations)
Thu Feb 4 22:47:07 2010 UTC (10 years, 4 months ago) by plugwash
File size: 1972 byte(s)
set line ending property on files to hopefully avoid line ending problems in future

1 { Copyright (C) 2005 Bas Steendijk and Peter Green
2 For conditions of distribution and use, see copyright notice in zlib_license.txt
3 which is included in the package
4 ----------------------------------------------------------------------------- }
5
6 unit ltimevalstuff;
7 interface
8
9 {$ifdef win32}
10 type
11 ttimeval = record
12 tv_sec : longint;
13 tv_usec : longint;
14 end;
15 {$else}
16 {$ifdef ver1_0}
17 uses linux;
18 {$else}
19 uses baseunix,unix,unixutil,sockets;
20 {$endif}
21 {$endif}
22
23
24 procedure tv_add(var tv:ttimeval;msec:integer);
25 function tv_compare(const tv1,tv2:ttimeval):boolean;
26 procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);
27 procedure msectotimeval(var tv:ttimeval;msec:integer);
28
29 //tv_invalidtimebig will always compare as greater than any valid timeval
30 //unfortunately unixstuff.inc hasn't worked it's magic yet so we
31 //have to ifdef this manually.
32 const
33 {$ifdef ver1_0}
34 tv_invalidtimebig : ttimeval = (sec:maxlongint;usec:maxlongint);
35 {$else}
36 tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);
37 {$endif}
38 implementation
39
40 {$i unixstuff.inc}
41
42 {add nn msec to tv}
43 procedure tv_add(var tv:ttimeval;msec:integer);
44 begin
45 inc(tv.tv_usec,msec*1000);
46 inc(tv.tv_sec,tv.tv_usec div 1000000);
47 tv.tv_usec := tv.tv_usec mod 1000000;
48 end;
49
50 {tv1 >= tv2}
51 function tv_compare(const tv1,tv2:ttimeval):boolean;
52 begin
53 if tv1.tv_sec = tv2.tv_sec then begin
54 result := tv1.tv_usec >= tv2.tv_usec;
55 end else result := tv1.tv_sec > tv2.tv_sec;
56 end;
57
58 procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);
59 begin
60 dec(tv.tv_usec,tv2.tv_usec);
61 if tv.tv_usec < 0 then begin
62 inc(tv.tv_usec,1000000);
63 dec(tv.tv_sec)
64 end;
65 dec(tv.tv_sec,tv2.tv_sec);
66 end;
67
68 procedure msectotimeval(var tv:ttimeval;msec:integer);
69 begin
70 tv.tv_sec := msec div 1000;
71 tv.tv_usec := (msec mod 1000)*1000;
72 end;
73
74 end.

Properties

Name Value
svn:eol-style CRLF
svn:executable
svn:mergeinfo

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.22