Of course on second thoughts it's not surprising that fopen() allows opening directories: library implementors also wanted to avoid unnecessary overhead. Linux's open() accepts a flag to open JUST directories, but none to specify JUST files.
I would make OPEN behave the same way on all platforms, and then make a separate command like RAWOPEN or UNIXOPEN or something like that.
Already exists: use open() from FB's Unix headers. Using FB file handles on top of stdio FILEs on top of OS file descriptors seems like a bad idea. (I personally wouldn't touch the C->FB translated unix headers though; they're non-portable and full of errors and omissions)
counting_pine wrote:Does it produce error codes if you try to Get/Put with the file handle, or does it just "succeed"?
The underlying fread/fwrite calls will fail, so surely the FB functions forward the errors.
It wouldn't be entirely down to me, but I'd vote to accept a "clean" patch if there's not much overhead. By that I mean, if it can be tested with a function of the same kind as fopen, or if a test can be performed on the opened handle, then that would be OK.
Yes, you would use fstat(), which is faster than stat(). However that's of course platform specific, while the OPEN implementation in libfb_dev_file_open.c is in shared code. So it seems that to add this check you would have to add a hook to a platform-specific check elsewhere.