Connecting Tech Pros Worldwide Forums | Help | Site Map

Ways fopen() Failes

Nathaniel Wingard
Guest
 
Posts: n/a
#1: Nov 13 '05
I am trying to do a basic file check (see if the file exists) and I am using
the command fopen(argv[1], "r") to check. However I am afraid that it may
fail even if the file does exist if the file is on a networked drive
(similar to the way rename() dies. It isn't in any of the documentation,
does anyone know if it has any problems like this?
Thanks
Nathaniel





Mike Wahler
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Ways fopen() Failes


Nathaniel Wingard <Parinioa@hotmail.com> wrote in message
news:bk7kno$blk$1@msunews.cl.msu.edu...[color=blue]
> I am trying to do a basic file check (see if the file exists)[/color]

There's no way to do that with standard C.
[color=blue]
>and I am using
> the command fopen(argv[1], "r") to check.[/color]

The only thing you can learn from 'fopen()'s return value
is, was the file opened successfully or not. *Why* cannot
be determined.
[color=blue]
> However I am afraid that it may
> fail even if the file does exist if the file is on a networked drive[/color]

Yes, depending upon the environment, there are any number of
reasons that a file could not be opened.
[color=blue]
>
> (similar to the way rename() dies.[/color]

'rename()' will return zero if successful, nonzero if not.
If it fails, why cannot be determined.
[color=blue]
> It isn't in any of the documentation,[/color]

It's not part of the standard C language.
[color=blue]
> does anyone know if it has any problems like this?[/color]

I don't see any 'problem'.

What you're asking about is platform-specific behavior.
Consult your implementation and/or operating system
documentation. Most OS's feature API calls for more
intimate interaction with e.g. a file system.

-Mike




Eric Sosman
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Ways fopen() Failes


Nathaniel Wingard wrote:[color=blue]
>
> I am trying to do a basic file check (see if the file exists) and I am using
> the command fopen(argv[1], "r") to check. However I am afraid that it may
> fail even if the file does exist if the file is on a networked drive
> (similar to the way rename() dies. It isn't in any of the documentation,
> does anyone know if it has any problems like this?[/color]

This is Question 19.11 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

--
Eric.Sosman@sun.com
Closed Thread