Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-12

fstat usage

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Francisco Reyes

Trying the fstat function and don't seem to be getting the right values for ctime, mtime and atime.

-- filedate.pp
uses BaseUnix,DateUtils,SysUtils;
var
  info : stat ;
begin
  if fpstat ('myfile.txt' , info) 0 then
    begin
      writeln ('Fstat failed . Errno : ' , fpgeterrno) ;
      halt ( 1 ) ;
    end ;
  writeln ;
  writeln ('atime  : ' , DateTimeToStr(info.st_atime ));
  writeln ('mtime  : ' , DateTimeToStr(info.st_mtime ));
  writeln ('ctime  : ' , DateTimeToStr(info.st_ctime ));
  writeln ('Now STR: ', DateTimeToStr(Now));
  writeln ('Mod diff:' , DaySpan(Now,info.st_mtime));
  writeln ('mtime raw: ', info.st_mtime );
  writeln (' Now  raw: ', Now);
end .

touch mfyle.txt
fpc filedate.pp
./filedate.pp
atime : 6-9-88<--
mtime : 6-9-88<--
ctime : 6-9-88<--
Now STR: 5-12-08 22:15:08
Mod diff: 1.22849351907281E+009
mtime raw: 1228533307
Now raw: 3.97879271865278E+004

I was expecting atime, mtime and ctime to be very close to 'Now'.

The file date is December 5, 2008 as shown on the OS ll myfile.txt
-rw-r--r-- 1 fran users 16 2008-12-05 22:15 myfile.txt

Any suggestions on what I am missing would be greatly appreciated.

Francisco Reyes
to Micha Nelissen
Micha Nelissen wrote 5 lines
Francisco Reyes wrote: > Trying the fstat function and don't seem to be getting the right values > for ctime, mtime and atime. What OS and CPU ?

Tried FreeBSD 6.3 on i386, AMD CPU and Opensuse 10.3 64 bits AMD cpu

Francisco Reyes
to Francisco Reyes: Trying the fstat function and don't seem to be getting the right values for ctime, mtime…
Francisco Reyes wrote 39 lines
Trying the fstat function and don't seem to be getting the right values for ctime, mtime and atime. -- filedate.pp uses BaseUnix,DateUtils,SysUtils; var info : stat ; begin if fpstat ('myfile.txt' , info) 0 then begin writeln ('Fstat failed . Errno : ' , fpgeterrno) ; halt ( 1 ) ; end ; writeln ; writeln ('atime : ' , DateTimeToStr(info.st_atime )); writeln ('mtime : ' , DateTimeToStr(info.st_mtime )); writeln ('ctime : ' , DateTimeToStr(info.st_ctime )); writeln ('Now STR: ', DateTimeToStr(Now)); writeln ('Mod diff:' , DaySpan(Now,info.st_mtime)); writeln ('mtime raw: ', info.st_mtime ); writeln (' Now raw: ', Now); end . touch mfyle.txt fpc filedate.pp ./filedate.pp atime : 6-9-88<-- mtime : 6-9-88<-- ctime : 6-9-88<-- Now STR: 5-12-08 22:15:08 Mod diff: 1.22849351907281E+009 mtime raw: 1228533307 Now raw: 3.97879271865278E+004 I was expecting atime, mtime and ctime to be very close to 'Now'. The file date is December 5, 2008 as shown on the OS ll myfile.txt -rw-r--r-- 1 fran users 16 2008-12-05 22:15 myfile.txt

What other function can I use instead of fpstat?
Perhaps a different function in another RTL library?

Need to be able to have the program work on both FreeBSD and Linux. Any pointers greatly appreciated.

Pete Cervasio
to Francisco Reyes
Francisco Reyes wrote
Francisco Reyes writes: > Trying the fstat function and don't seem to be getting the right values > for ctime, mtime and atime.

Those values are Unix timestamp values. You need to convert them into TDateTime values. Look for UnixToDateTime and DateTimeToUnix in DateUtils.

Best regards,
Pete C.

Francisco Reyes
to Pete Cervasio
Pete Cervasio wrote
TDateTime values. Look for UnixToDateTime and DateTimeToUnix in DateUtils.

The documentation I have must be old (even though I got it a few days ago from the website). It says those functions are not implemented, yet I was able to use it.

Is the time displayed in UTC? Seems to be.
Any way to make the time displayed be my timezone?

Francisco Reyes
to Francisco Reyes
Francisco Reyes wrote
Is the time displayed in UTC? Seems to be. Any way to make the time displayed be my timezone?

Nevermind that...
Was confused because the date was in a different format..

You pointed me in the right direction and finished the program.