fpsettimeofday, milliseconds and vbox lazarus / 32-Linux ---------------------------------------------------------------------- pkacperski · 2014-06-23 13:28 Hello I've stumbled upon quite a strange problem with fpsettimeofday from 'BaseUnix' module. I have this simple piece of code: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var    tv : timeval; begin    fpgettimeofday(@tv, nil);    Form1.Memo1.Append('tv.tv_sec = ' + IntToStr(tv.tv_sec) + ', tv.tv_usec = ' + IntToStr(tv.tv_usec));    tv.tv_usec := 30000;    fpsettimeofday(@tv, nil);    fpgettimeofday(@tv, nil);    Form1.Memo1.Append('tv.tv_sec = ' + IntToStr(tv.tv_sec) + ', tv.tv_usec = ' + IntToStr(tv.tv_usec)); end;              I've tested this code on two systems: Ubuntu 64-bit running natively on my PC and Ubuntu 32-bit running in Oracle VirtualBox hosted in the former one. When run on my PC, this code behaves as expected: Code: [Select]tv.tv_sec = 1403529872, tv.tv_usec = 892197 tv.tv_sec = 1403529872, tv.tv_usec = 30009 tv.tv_sec = 1403529873, tv.tv_usec = 61792 tv.tv_sec = 1403529873, tv.tv_usec = 30029 ...but when run on VBox, fpsettimeofday seems to ignore milliseconds field and sets time as if it was set to 0: Code: [Select]tv.tv_sec = 1403529999, tv.tv_usec = 708589 tv.tv_sec = 1403529999, tv.tv_usec = 322 tv.tv_sec = 1403529999, tv.tv_usec = 552320 tv.tv_sec = 1403529999, tv.tv_usec = 247 Any idea? ---------------------------------------------------------------------- marcov · 2014-06-23 13:53 On 32-bit it seems that the older stime() syscall is used instead of settimeofday. Stime only sets the tv_sec part, so not the nanosecond and timezone parts. (unix/settimeo.inc, the define is set in linux/osdefs.inc) I assume this was done for compatibility with older kernels, but probably currently supported kernels don't need this anymore.