[fpc-pascal] Why opening a file for write fails in fpc 2.6?

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Oct 31 13:42:13 CET 2012


On 31 Oct 2012, at 13:29, Giuliano Colla wrote:

> In Linux environment the following code:
>
>  try
>    USBOut := FileOpen(UsbDev,fmOpenWrite);
>  except
>    result := True;
>  end;
>
> is used in a Lazarus application to get a handle to write to an USB  
> device, and did work fine in fpc 2.4.
>
> I migrated the application to Lazarus 1.0 wich uses fpc 2.6, and it  
> stopped working. FileOpen returns -1, without rising an exception,  
> which made me struggle to find out what was happening.

FPC 2.6 added support for file locking on Unix platforms. You probably  
should use

   USBOut := FileOpen(UsbDev,fmOpenWrite or fmShareDenyNone);

Otherwise FileOpen will try to get an exclusive (write) lock on that  
device, which may well not be possible.

> Moreover I don't understand why the call returns a -1, meaning that  
> the Open failed, without rising an exception.

Does FileOpen raise an exception in Delphi when locking fails?


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20121031/bfcb05e1/attachment.html>


More information about the fpc-pascal mailing list