[fpc-devel] Question regarding FileSetDate implementation

Sven Barth pascaldragon at googlemail.com
Tue Nov 9 10:09:22 CET 2010


Hello together!

As you might have noticed, I'm working on the NativeNT RTL again and 
discover some nice FPC_HAS_FEATURE_* and THandle problems on the way. 
Now I've found another one and I'd like to know how this should be fixed:

FileSetDate in SysUtils (the filename variant) returns a LongInt, but 
someone thought it was a good idea to return the (invalid) file handle 
if the FileOpen call fails. Thus I get a compile error, cause my handle 
type on NativeNT is a Pointer.

The documentation states that a negative value is returned in case of an 
error. Granted, INVALID_HANDLE_VALUE is negative, but that's no reason 
to assign the value of the handle there (what if some OS decides that an 
invalid handle is 42 instead of LongWord(-1)?)

==== source begin ====

   Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
   Var
     fd : THandle;
   begin
     { at least windows requires fmOpenWrite here }
     fd:=FileOpen(FileName,fmOpenWrite);
     If (Fd<>feInvalidHandle) then
       try
         Result:=FileSetDate(fd,Age);
       finally
         FileClose(fd);
       end
     else
       Result:=fd; // this is the problematic place... should we just 
return -1 here?
   end;

==== source end ====

Regards,
Sven



More information about the fpc-devel mailing list