[comp.lang.c] When will fopen fail?

markh@csd4.csd.uwm.edu (Mark William Hopkins) (04/17/91)

   Assuming all the subdirectories are there and writeable (on UNIX or
MS-DOS), when does

		     FP = fopen("...", "w");

fail and return FP == NULL?

stanley@phoenix.com (John Stanley) (04/17/91)

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

> markh@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.

tom@itc.univie.ac.at (Tom Kovar) (04/17/91)

In article <11079@uwm.edu> markh@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?

 ... file system full
 ... user quota exceeded
 ... file system mounted read only

 ... any other ideas??
							...Tom

gordon@osiris.cso.uiuc.edu (John Gordon) (04/18/91)

markh@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.  Or if the
filename is actually a device.

---
John Gordon
Internet: gordon@osiris.cso.uiuc.edu        #include <disclaimer.h>
          gordon@cerl.cecer.army.mil       #include <clever_saying.h>

stanley@phoenix.com (John Stanley) (04/18/91)

markh@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?

   On MS-DOS, under TC 2.0, all the time. Perror returns "no such file or
directory".

gwyn@smoke.brl.mil (Doug Gwyn) (04/18/91)

In article <1991Apr17.202735.12427@ux1.cso.uiuc.edu> gordon@osiris.cso.uiuc.edu (John Gordon) writes:
>	Well, it could fail if the process has reached the limit of
>simultaneous open files.  Or if the filename is not valid.  Or if the
>filename is actually a device.

Or if the network link is down, or if proper access permissions are
not present, or ...

Basically, there are too many possible reasons for failure to make it
practical to worry about what they all are in detail.

cjkuo@locus.com (Chengi Jimmy Kuo) (04/19/91)

stanley@phoenix.com (John Stanley) writes:

>markh@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?

>   On MS-DOS, under TC 2.0, all the time. Perror returns "no such file or
>directory".

Because "..." is an illegal filename under DOS.
-- 
cjkuo@locus.com
"The correct answer to an either/or question is both!"

berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) (04/19/91)

Tom Kovar writes:
>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?

> ... file system full
> ... user quota exceeded
> ... file system mounted read only

Or no memory left (fopen does a malloc!)
--
Sincerely,                 berg@marvin.e17.physik.tu-muenchen.de
           Stephen R. van den Berg.
"I code it in 5 min, optimize it in 90 min, because it's so well optimized:
it runs in only 5 min.  Actually, most of the time I optimize programs."