|Just another Perl shrine|
F_GETFL and Win32by dragonchild (Archbishop)
|on Mar 08, 2006 at 02:58 UTC||Need Help??|
dragonchild has asked for the
wisdom of the Perl Monks concerning the following question:
(This is yet another reason why I hate programming for Win32, even if only through CPAN.)
In DBM::Deep 0.98 and above, we added the feature that you could pass in your own filehandle instead of a filename. (This allows you to use the *DATA filehandle as a DBM::Deep file.) The only issue is that DBM::Deep opens its filehandles as read-write handles. Potentially, you could pass us a read-only filehandle. (I'm not even going to comment on the stupidity of passing a write-only filehandle to DBM::Deep.)
If you do, then accidentally try to modify the data, then a warning gets popped up in print() saying "Cannot print to a closed filehandle". Fatal doesn't work because print() cannot be overridden. While I could trap the warning, I'd still prefer to detect the fact that the filehandle isn't writable and throw an error.
I found the following code somewhere on Perlmonks (Thanks, Zaxo!) and it does the trick:
The code works great . . . on systems whose Fcntl have defined F_GETFL. Unfortunately, that doesn't seem to include Win32 (at least not for ActiveState 5.8.6).
Other than disabling that function for Win32, how should I go about fixing this problem?
My criteria for good software: