summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/libc/src/stime.inc
blob: 22e690ba3fbcdca5a2d26808d7e6743c6708f257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{ ---------------------------------------------------------------------
    Macros from sys/time.h
  ---------------------------------------------------------------------}


Procedure TIMEVAL_TO_TIMESPEC(const tv: TTimeVal; var ts: TTimeSpec);
begin
  ts.tv_sec:=tv.tv_sec;
  ts.tv_nsec:=tv.tv_usec*1000;
end;


Procedure TIMESPEC_TO_TIMEVAL(var tv: TTimeVal; const ts: TTimeSpec);
begin
  tv.tv_sec:=ts.tv_sec;
  tv.tv_usec:=ts.tv_nsec div 1000;
end;


Function timerisset(const Value: TTimeVal): Boolean;
begin
  Result:=(Value.tv_sec<>0) or (Value.tv_usec<>0);
end;


Procedure timerclear(var Value: TTimeVal);
begin
  Value.tv_sec:=0;
  Value.tv_usec:=0;
end;


Function __timercmp(const a, b: TTimeVal): Integer;

begin
  if a.tv_sec=b.tv_sec then
    begin
    if a.tv_usec>b.tv_usec then
      Result:=1
    else if a.tv_usec<b.tv_usec then
      Result:=-1
    else
      Result:=0;
    end
  else
    begin
    if a.tv_sec>b.tv_sec then
      Result:=1
    else
      Result:=-1;
    end;
end;


Function timeradd(const a, b: TTimeVal): TTimeVal;

begin
  Result.tv_sec:=a.tv_sec+b.tv_sec;
  Result.tv_usec:=a.tv_usec+b.tv_usec;
  if Result.tv_usec>=1000000 then
    begin
    Inc(Result.tv_sec);
    Dec(Result.tv_usec, 1000000);
    end;
end;


Function timersub(const a, b: TTimeVal): TTimeVal;

begin
  Result.tv_sec:=a.tv_sec-b.tv_sec;
  Result.tv_usec:=a.tv_usec-b.tv_usec;
  if Result.tv_usec<0 then
    begin
    Dec(Result.tv_sec);
    Inc(Result.tv_usec,1000000);
    end;
end;