C语言,
函数形式:int fchdir(int fd);
函数简介
函数形式:int fchdir(int fd);
返回值:成功返回0,失败返回-1
示例程序
//Linux环境下(Linux deepin 11.06RC2)测试通过
#include
#include
#include
int main(void)
{
long cur_path_len;
char * cur_work_dir;
int fd;//file descriptor
//get the max length of the directory
{
return 1;
}
//print the path length
//Allocate memory for the array cur_work_dir
if ((cur_work_dir = (char *) malloc(cur_path_len)) == NULL)
{
return 1;
}
//Get current working directory
if (getcwd(cur_work_dir, cur_path_len) == NULL)
{
return 1;
}
//Print the current work directory
//free the the memory
free (cur_work_dir);
//Get current file descriptor
{
}
//change the current working directory
{
return 1;
}
//Allocate memory for the array cur_work_dir
if ((cur_work_dir = (char *) malloc(cur_path_len)) == NULL)
{
return 1;
}
//Get current working directory
if (getcwd(cur_work_dir, cur_path_len) == NULL)
{
return 1;
}
//Print the current work directory
//free the the memory
free (cur_work_dir);
//Use the function fchdir();
if (fchdir(fd) == -1)
{
return 1;
}
//Allocate memory for the array cur_work_dir
if ((cur_work_dir = (char *) malloc(cur_path_len)) == NULL)
{
return 1;
}
//Get current working directory
if (getcwd(cur_work_dir, cur_path_len) == NULL)
{
return 1;
}
//Print the current work directory
//free the the memory
free (cur_work_dir);
return 0;
}