Ways fopen() Failes

Discussion in 'C Programming' started by Nathaniel Wingard, Sep 16, 2003.

  1. 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
    Nathaniel Wingard, Sep 16, 2003
    #1
    1. Advertising

  2. Nathaniel Wingard

    Eric Sosman Guest

    Nathaniel Wingard wrote:
    >
    > 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

    --
    Eric Sosman, Sep 16, 2003
    #2
    1. Advertising

  3. Nathaniel Wingard

    Mike Wahler Guest

    Nathaniel Wingard <> wrote in message
    news:bk7kno$blk$...
    > 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
    Mike Wahler, Sep 16, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    485
    isamura
    Dec 9, 2005
  2. Nonee
    Replies:
    2
    Views:
    2,648
    Neredbojias
    Oct 25, 2005
  3. wes weston

    askstring => grab failes

    wes weston, Apr 26, 2004, in forum: Python
    Replies:
    1
    Views:
    455
    klappnase
    Apr 27, 2004
  4. Michel Rouzic
    Replies:
    4
    Views:
    1,831
    Michel Rouzic
    Apr 28, 2008
  5. Howard
    Replies:
    1
    Views:
    457
    Bob Barrows [MVP]
    Jul 6, 2004
Loading...

Share This Page