# include <stdio.h>
# include <stdlib.h>
# include <sys/stat.h>
# include <unistd.h>
# include <sys/types.h>
# include <dirent.h>
ino_t get_inode(char * name);
void pwd_dir(ino_t node);
int main(void)
{
pwd_dir(get_inode("."));
printf("\n");
return 0;
}
void pwd_dir(ino_t node)
{
struct dirent * dir;
DIR * buf_dir;
chdir("..");
if(node == get_inode("."))
return;
buf_dir = opendir(".");
while((dir = readdir(buf_dir)) != NULL)
{
if(dir->d_ino == node)
{
pwd_dir(get_inode("."));
printf("/%s", dir->d_name);
}
}
}
ino_t get_inode(char * name)
{
struct stat current_name;
if(stat(name, ¤t_name) == -1)
{
fprintf(stderr, "Cannot stat");
perror(name);
exit(1);
}
return current_name.st_ino;
}
类似pwd命令程序
最新推荐文章于 2023-12-15 01:34:41 发布