Sign in Join

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

Mailing lists / fpc-devel / 2011-11

correct usage of fpstat() inside FileAge() function

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

This is the implementation of FileAge() under FPC 2.6.0 (the upcoming release)

---------------------------------------
Function FileAge (Const FileName : String): Longint;
Var Info : Stat;
begin
  If  (fpstat (pointer(FileName),Info)<0) or fpS_ISDIR(info.st_mode) then
    exit(-1)
  else
    Result:=UnixToWinAge(info.st_mtime);
end;
---------------------------------------

The FPC documentation for fpstat() mentions that a zero return value means success, and any non-zero value means failure.

So shouldn't the above usage rather be written as follows (just like the example code show in the FPC documentation):

  If  (fpstat (pointer(FileName),Info)0) or fpS_ISDIR(info.st_mode) then
     ....
Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Unknown author
to Graeme Geldenhuys

The docs should be adapted.
Normally the function returns -1 on failure, so the code is OK.

Michael.

Graeme Geldenhuys wrote 38 lines
Hi, This is the implementation of FileAge() under FPC 2.6.0 (the upcoming release) --------------------------------------- Function FileAge (Const FileName : String): Longint; Var Info : Stat; begin If (fpstat (pointer(FileName),Info)<0) or fpS_ISDIR(info.st_mode) then exit(-1) else Result:=UnixToWinAge(info.st_mtime); end; --------------------------------------- The FPC documentation for fpstat() mentions that a zero return value means success, and any non-zero value means failure. So shouldn't the above usage rather be written as follows (just like the example code show in the FPC documentation): If (fpstat (pointer(FileName),Info)0) or fpS_ISDIR(info.st_mode) then .... -- Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email