function unixtimefloat:float;\r
 var\r
   tv:ttimeval;\r
+  sec:tunixtimeint;\r
 begin\r
   gettimeofday(tv);\r
-  result := tv.tv_sec+(tv.tv_usec/1000000);\r
+  sec := tv.tv_sec;\r
+  {$ifndef cpu64}\r
+  if (sec < 0) then inc(sec,$100000000); //tv_sec is 32 bits\r
+  {$endif}\r
+  result := sec+(tv.tv_usec/1000000);\r
 end;\r
 \r
 {$ifdef linux}\r
 function unixtimeint:tunixtimeint;\r
 var\r
   tv:ttimeval;\r
+  sec:tunixtimeint;\r
 begin\r
   gettimeofday(tv);\r
-  result := tv.tv_sec;\r
+  sec := tv.tv_sec;\r
+  {$ifndef cpu64}\r
+  if (sec < 0) then inc(sec,$100000000); //tv_sec is 32 bits\r
+  {$endif}\r
+  result := sec;\r
 end;\r
 \r
 {------------------------------ end of *nix/freepascal section}\r