#include <unistd.h>
|
|
int
chdir (const char *path); |
|
int
fchdir (int fd); |
The fchdir system call causes the directory referenced by fd to become the current working directory, the starting point for path searches of pathnames not beginning with a slash, ‘/.’
/**
* Detailed description : This test code demonstrates usage of chdir system call
*
* Preconditions : "Example" directory should be present in current working
directory.
**/
#include <unistd.h>
int main()
{
if(chdir("Example") < 0 )
{
printf("Failed to change working directory \n");
return -1 ;
}
printf("Working directory changed \n");
return 0 ;
}
Output
Working directory changed
#include<unistd.h>
#include<stdio.h>
int test_fchdir()
{
int retVal;
int rmdr;
int mkdr = mkdir("test_dir", S_IWUSR);
if( !mkdr )
{
int opn = open("test_dir", O_RDONLY);
if( opn != -1 )
{
retVal = fchdir( opn );
if( !retVal )
{
printf("Fchdir passed");
}
else
{
printf("Failed");
}
int cls = close(opn);
}
else
{
printf("Failed");
}
rmdr = rmdir("test_dir");
}
else
{
printf("Failed");
}
}
Output
Fchdir passed
| [ENOTDIR] | |
| The file descriptor does not reference a directory. | |
| [EBADF] | |
| The argument fd is not a valid file descriptor. | |
|
© 2005-2007 Nokia |