Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/chdir.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/chdir.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/chdir.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/chdir.html on line 8
Change the current working directory
#include <unistd.h>
int chdir( const char* path );
- path
- The new current working directory.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The chdir() function changes the current working directory to
path, which can be relative to the current working directory or
an absolute path name.
- 0
- Success.
- -1
- An error occurred (errno is set).
- EACCES
- Search permission is denied for a component of path.
- ELOOP
- Too many levels of symbolic links or prefixes.
- ENAMETOOLONG
- The path argument is longer than PATH_MAX,
or a pathname component is longer than NAME_MAX.
- ENOENT
- The specified path doesn't exist, or path
is an empty string.
- ENOMEM
- There wasn't enough memory to allocate a control structure.
- ENOSYS
- The chdir() function isn't implemented for the filesystem specified
in path.
- ENOTDIR
- A component of path is not a directory.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main( int argc, char* argv[] )
{
if( argc != 2 ) {
fprintf( stderr, "Use: cd <directory>\n" );
return EXIT_FAILURE;
}
if( chdir( argv[1] ) == 0 ) {
printf( "Directory changed to %s\n", argv[1] );
return EXIT_SUCCESS;
} else {
perror( argv[1] );
return EXIT_FAILURE;
}
}
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
There's only one current working directory per process.
In a multithreaded application, any thread calling
chdir() will change the
current working directory for all threads in that process.
errno,
fchdir(),
getcwd(),
mkdir(),
rmdir()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/chdir.html on line 197
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/chdir.html on line 197