Thread: errno, rmdir

  1. #1

    Question errno, rmdir

    The general structure of the code is like this.

    cout << "Before rmdir errno is " << errno << endl;
    result = rmdir(string_variable);
    k = errno;
    cout << "After rmdir errno is " << k << endl;

    cout << "result is " << result << endl;
    if(result == -1) {

    if( (k = this) || (k == that) || (k == somethingelse))
    do this;
    else {
    switch(k) {
    case ENOTDIR: //All listed values for
    cout << "ENOTDIR"; // errno in man pages
    break; // for rmdir
    cout << "None of the above";
    cout << endl;
    perror("Error is");

    The output for the code is:

    Before rmdir errno is 0
    After rmdir errno is 0
    result is -1
    None of the above
    The error is 0
    Error is: Invalid argument

    This is the output shown when rmdir does not successfully remove my directory. This happens when the directory given is actually there. Errno still prints out to zero but perror shows an error. This makes no sense to me. Has anyone came across a problem like this before? I have already asked another software engineer and he has already given up on this problem. I am frustrated and would like to resolve this.

    Any help is greatly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Instead of all that messing about, which does who knows what to errno, how about simply trying
    result = rmdir(string_variable);
    if ( result == -1 ) {
        perror( "Failed to rmdir" );
    > (k = this)
    Is this a typo?
    Because you perform this assignment (losing the original value of k), then do some switch/case stuff.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Oh, sorry about that, there is supposed to be another bracket after the if statement, it is somewhat written in pseudocode just so I am not including anything that could be "considered" company information.

  4. #4
    Sorry again, the brackets are fine.

    "do this" just refers to some code which isn't executed when I am testing. The actual code was not included so there is no "company sensitive" information.

    The reason I wanted to check the actual value of errno is so I can look it up in the man page and get a better idea of why the code executing rmdir is not working right.

    I try to use rmdir to remove a directory called /tmp/test/tmp and it does not work. It should work though.

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. where from extern int errno came ?
    By jabka in forum C Programming
    Replies: 2
    Last Post: 10-14-2007, 05:25 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