Ways fopen() Failes

N

Nathaniel Wingard

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
 
E

Eric Sosman

Nathaniel said:
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?

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

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

Mike Wahler

Nathaniel Wingard said:
I am trying to do a basic file check (see if the file exists)

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

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

Yes, depending upon the environment, there are any number of
reasons that a file could not be opened.
(similar to the way rename() dies.

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

It's not part of the standard C language.
does anyone know if it has any problems like this?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fopen 17
fopen() questions 17
Command Line Arguments 0
fopen extensions 3
fopen - file and directories ?? 15
The different ways to use argv 8
questions on ftell and fopen 25
file exists or not before calling fopen 10

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top