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
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to