When will fopen fail?

John Stanley stanley at phoenix.com
Wed Apr 17 17:35:16 AEST 1991


gordon at osiris.cso.uiuc.edu (John Gordon) writes:

> markh at csd4.csd.uwm.edu (Mark William Hopkins) writes:
> 
> 
> >   Assuming all the subdirectories are there and writeable (on UNIX or
> >MS-DOS), when does
> 
> >		     FP = fopen("...", "w");
> 
> >fail and return FP == NULL?
> 
> 	Well, it could fail if the process has reached the limit of
> simultaneous open files.  Or if the filename is not valid.  

   Aye to both.

> Or if the
> filename is actually a device.

   Only if the device is read-only, or no access, for the user, or if it is
a non-character device (for UNIX).

   Other failures:  no disk space. no more inodes. (maybe) file exists and
is not writable.

   Perhaps we should be asking "why do you ask?" Is this a case of some
code you have written failing and you want us to debug it? If so, I suggest
you add a test for FP and user perror() to report the actual problem.



More information about the Comp.lang.c mailing list