Thread: File functions

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    40

    File functions

    Does anyone know if this is a file function that allows me to check for the existence of a file before I try to open it?
    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    40
    I was afraid that you were going to say that.
    There must be some other return codes in errno.h that I can also use, I will just have to trawl through that.
    Thanks

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>There must be some other return codes in errno.h that I can also use
    Use for what exactly? You can get formatted error messages with strerror().

    If you're after more control than fopen() can provide, you'll have to use an compiler specific function, like stat() , which is detailed in the unix FAQ
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    40
    For determining the failure reason and returning a more meaningful message to the log file. I havent come across strerror() before, but looking at the man page it looks like it will do what I want. If I use the strerror function inside the fprintf function it should return the error message string to the log file, as:

    fprintf(OUT_FILE, "Error: Error No: %i, Error message: %s\n", errno, strerror(errno));

    Thanks v.helpful
    Peter

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    If you're doing that, you might find these functions useful too (if you want to make your log writing code more friendly)

    Code:
    void LogMessage(char *fmt, ...)
    {
        va_list arglist;
        va_start(arglist, fmt);
        vfprintf(stderr, fmt, arglist);
        va_end( arglist );
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM