stime.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. { ---------------------------------------------------------------------
  2. Macros from sys/time.h
  3. ---------------------------------------------------------------------}
  4. Procedure TIMEVAL_TO_TIMESPEC(const tv: TTimeVal; var ts: TTimeSpec);
  5. begin
  6. ts.tv_sec:=tv.tv_sec;
  7. ts.tv_nsec:=tv.tv_usec*1000;
  8. end;
  9. Procedure TIMESPEC_TO_TIMEVAL(var tv: TTimeVal; const ts: TTimeSpec);
  10. begin
  11. tv.tv_sec:=ts.tv_sec;
  12. tv.tv_usec:=ts.tv_nsec div 1000;
  13. end;
  14. Function timerisset(const Value: TTimeVal): Boolean;
  15. begin
  16. Result:=(Value.tv_sec<>0) or (Value.tv_usec<>0);
  17. end;
  18. Procedure timerclear(var Value: TTimeVal);
  19. begin
  20. Value.tv_sec:=0;
  21. Value.tv_usec:=0;
  22. end;
  23. Function __timercmp(const a, b: TTimeVal): Integer;
  24. begin
  25. if a.tv_sec=b.tv_sec then
  26. begin
  27. if a.tv_usec>b.tv_usec then
  28. Result:=1
  29. else if a.tv_usec<b.tv_usec then
  30. Result:=-1
  31. else
  32. Result:=0;
  33. end
  34. else
  35. begin
  36. if a.tv_sec>b.tv_sec then
  37. Result:=1
  38. else
  39. Result:=-1;
  40. end;
  41. end;
  42. Function timeradd(const a, b: TTimeVal): TTimeVal;
  43. begin
  44. Result.tv_sec:=a.tv_sec+b.tv_sec;
  45. Result.tv_usec:=a.tv_usec+b.tv_usec;
  46. if Result.tv_usec>=1000000 then
  47. begin
  48. Inc(Result.tv_sec);
  49. Dec(Result.tv_usec, 1000000);
  50. end;
  51. end;
  52. Function timersub(const a, b: TTimeVal): TTimeVal;
  53. begin
  54. Result.tv_sec:=a.tv_sec-b.tv_sec;
  55. Result.tv_usec:=a.tv_usec-b.tv_usec;
  56. if Result.tv_usec<0 then
  57. begin
  58. Dec(Result.tv_sec);
  59. Inc(Result.tv_usec,1000000);
  60. end;
  61. end;