Re: opening a file
- From: Chris Mattern <syscjm@xxxxxxxxxxxxxx>
- Date: Wed, 14 Jan 2009 08:30:04 -0600
On 2009-01-14, cartercc <cartercc@xxxxxxxxx> wrote:
On Jan 10, 8:07 am, Tad J McClellan <ta...@xxxxxxxxxxxxxx> wrote:
You should always, yes *always*, check the return value from open():
Like other ironclad rules, this also has exceptions. Using the 'or
die' construct has costs (albeit minimal) and when the costs outweigh
the benefit, you shouldn't use it. Example: opening the file is
tangential to the script so you don't care whether the file opens but
If you don't care whether the file opens, why are you opening it?
At the very least I think you'd need to know it didn't open so you
don't attempt to do I/O with it.
you DO care if the script dies.
Not every instance of checking what open() returns is done with "or die".
If you don't want the script to die, don't. But it is difficult in the
extreme to visualize a case where whether or not a file opened makes absolutely
no difference in what the rest of the script needs to do.
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
.
- Follow-Ups:
- Re: opening a file
- From: Peter J. Holzer
- Re: opening a file
- From: cartercc
- Re: opening a file
- References:
- opening a file
- From: George
- Re: opening a file
- From: cartercc
- Re: opening a file
- From: Jürgen Exner
- Re: opening a file
- From: George
- Re: opening a file
- From: Tad J McClellan
- Re: opening a file
- From: cartercc
- opening a file
- Prev by Date: Re: Using exec()
- Next by Date: Re: Using exec()
- Previous by thread: Re: opening a file
- Next by thread: Re: opening a file
- Index(es):
Relevant Pages
|