About Lesson
We can change the current working directory of the calling process using chdir function call.
int chdir(const char *pathname);
It takes the new directory as its argument. It returns 0 if there are no errors, otherwise -1.
To fetch the current working directory, we can call getcwd.
char *getcwd(char *buffer, size_t size);
We pass the address of a buffer and its size(in bytes), which should be large enough to accommodate the absolute path of the current working directory plus a terminating null byte(‘\0’). The function returns the buffer if successful, else returns NULL in case of error (for example if the buffer isn’t large enough to hold the absolute path).
To use chdir and getcwd, we need to include <unistd.h>.