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

Giuliano Colla giuliano.colla at fastwebnet.it
Wed Oct 31 13:29:07 CET 2012

In Linux environment the following code:

     USBOut := FileOpen(UsbDev,fmOpenWrite);
     result := True;

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.

To make it work I had to change from FileOpen to FileCreate, but I fail 
to understand the rationale behind that.
The file does exist because it's a physical device (/dev/ttyACM0), its 
existence is checked before that code, and the call to 
FileOpen(UsbDev,fmOpenRead) just before the above lines works properly 
so I don't understand while it should be created, and not just opened.

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

Is there a good reason for this change from 2.4 to 2.6 or it's just a bug?

Giuliano Colla

Before activating the tongue, make sure that the brain is connected 

More information about the fpc-pascal mailing list