-
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
....................
....................
default:
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.
-
Instead of all that messing about, which does who knows what to errno, how about simply trying
Code:
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.
-
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.
-
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.