Thread: mkdir function and errno

  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,336
    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, 12:21 PM
  2. errno function, error TLS/non TLS
    By fran.b in forum C Programming
    Replies: 13
    Last Post: 03-25-2009, 08:06 AM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  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, 04:10 PM