gtpc2m0o | C/C++ Language Support User's Guide |
This function changes the working directory.
Format
#include <unistd.h> int chdir(const char *pathname);
This function makes pathname your new working directory.
Normal Return
If successful, the chdir function changes the current working directory and returns 0.
Error Return
If unsuccessful, the chdir function does not change the working directory. Instead, it returns -1, and sets errno to one of the following:
Programming Considerations
None.
Examples
The following example shows the use of the chdir function.
#include <unistd.h> #include <stdio.h> main() { if (chdir("/tmp") != 0) perror("chdir() to /tmp failed"); if (chdir("/chdir/error") != 0) perror("chdir() to /CHDIR/ERROR failed"); }
Output
chdir() to /chdir/error failed: No such file or directory
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.