[cs631apue] hw2 questions

Jan Schaumann jschauma at stevens.edu
Fri Sep 23 22:13:45 EDT 2011


Rob Hoffmann <rhoffman at stevens.edu> wrote:

> When opening the source file to be read I have my program currently open  
> it in read only mode. However if that file is a directory the program  
> does not throw an error and continues as normal. Only if I set the mode  
> to read and write will the EISDIR error be thrown. Since opening it for  
> writing isn't really necessary, would I lose points if I set the program  
> to do that for the sake of catching that error, or should I be  
> approaching it from a different angle?

Take a look at stat(2).  That being covered in Monday's class, it's fine
to attempt to open(2) the first argument in RW mode, even if that's not
necessary for the operations of the tool other than catching this use
case.

-Jan


More information about the cs631apue mailing list