[fpc-pascal] Re: fstat usage

Francisco Reyes lists at stringsutils.com
Mon Dec 8 17:22:25 CET 2008


Francisco Reyes writes:

> 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.



More information about the fpc-pascal mailing list