[fpc-pascal] fstat usage

Francisco Reyes lists at stringsutils.com
Sat Dec 6 04:18:30 CET 2008


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.



More information about the fpc-pascal mailing list