mkdir function and errno

This is a discussion on mkdir function and errno within the C Programming forums, part of the General Programming Boards category; Hi everyone! Here is a silly question! The mkdir function: int mkdir (const char *filename, mode_t mode) has the following ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    28

    mkdir function and errno

    Hi everyone!
    Here is a silly question!

    The mkdir function:
    int mkdir (const char *filename, mode_t mode)

    has the following errnos:
    EACCES, EEXIST, EMLINK, etc....

    How can I find which one of these errors occurred when mkdir() function fails?

    Code:
    int status = mkdir(  "project1/testdir", (S_IRWXU | S_IRWXG | S_IRWXO)  )
    
    if(status == 0)
        printf("success");
    else
    {
        printf("error");
        // find which error occurred???
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    By examining the value of errno.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    28
    Quote Originally Posted by tabstop View Post
    By examining the value of errno.
    Thanks!
    I should've looked into the errno before asking this question..... silly me!

    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to clean errno?
    By kotoko in forum C Programming
    Replies: 20
    Last Post: 05-14-2009, 01:21 PM
  2. errno function, error TLS/non TLS
    By fran.b in forum C Programming
    Replies: 13
    Last Post: 03-25-2009, 09:06 AM
  3. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  4. connect() function, strange error
    By Mr_Miguel in forum C Programming
    Replies: 1
    Last Post: 12-12-2006, 06:51 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21