#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main()
{
open("hehe1",O_CREAT,0644);
char buf[1024] = {};
puts(getcwd(buf,sizeof(buf)));
int fd = open("..",O_RDONLY);
printf("%d\n",fchdir(fd));
open("haha1",O_CREAT,0644);
puts(getcwd(buf,sizeof(buf)));
}
在原文件夹下创建hehe1,并显示当前的工作目录
open(“hehe1”,O_CREAT,0644);
char buf[1024] = {};
puts(getcwd(buf,sizeof(buf)));
返回上一层文件夹并创建haha1,查看文件路径为已经改为上一层文件夹
int fd = open("…",O_RDONLY);
printf("%d\n",fchdir(fd));
open(“haha1”,O_CREAT,0644);
puts(getcwd(buf,sizeof(buf)));