#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h> ino_t get_inode(char *);
void printpathto(ino_t);
void inum_to_name(ino_t, char *, int); int main()
{
printpathto(get_inode("."));
printf("\n");
return 0;
} void printpathto(ino_t this_inode)
{
ino_t my_inode;
char its_name[BUFSIZ];
if (get_inode("..") != this_inode)
{
chdir("..");
inum_to_name(this_inode, its_name, BUFSIZ);
my_inode = get_inode(".");
printpathto(my_inode);
printf("/%s", its_name);
} } void inum_to_name(ino_t inode_to_find, char *namebuf, int buflen)
{
DIR *dir_ptr;
struct dirent *direntp;
dir_ptr = opendir(".");
if (dir_ptr == NULL)
{
perror(".");
exit(1);
}
while ((direntp = readdir(dir_ptr)) != NULL)
if (direntp->d_ino == inode_to_find)
{
strncpy(namebuf, direntp->d_name, buflen);
namebuf[buflen-1] = '\0';
closedir(dir_ptr);
return;
}
fprintf(stderr, "error looking for inum %d\n", inode_to_find);
exit(1);
} ino_t get_inode(char *fname)
{
struct stat info;
if (stat(fname, &info) == -1)
{
fprintf(stderr, "Cannot Stat");
perror(fname);
exit(1);
}
return info.st_ino;
}

pwd的实现的更多相关文章

  1. linux常用命令(2)pwd命令

    pwd 命令1 命令格式:pwd [选项]2 命令功能查看当前工作目录的完整路径3 常用参数一般不带任何参数如果目录是链接时:pwd -P 显示实际路径,而非使用链接路径4 常用实例:4.1 用pwd ...

  2. pwd命令

    [pwd]      打印当前的工作目录             pwd==print work director 命令格式: pwd [OPTION]... 命令功能: 打印当前工作目录的全路径 命 ...

  3. Linux命令学习总结:pwd命令

    命令简介: 该命令用来显示目前所在的工作目录.指令英文原义:print work directory 执行权限    :All User 指令所在路径:/usr/bin/pwd 或 /bin/pwd ...

  4. 每天一个linux命令(3):pwd命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  5. 【初级】linux pwd 命令详解及使用方法实战

    pwd:查看当前工作目录 前言: Linux中用 pwd 命令来查看”当前工作目录“的完整路径,就是经常提及的所在目录,多用在生产环境多级目录中查看当前所在路径,使用此命令能给运维人员/操作人员带来很 ...

  6. linux命令(3):pwd命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  7. linux-11 基本命令之 -工作期目录切换命令-pwd,cd,

    pwd 命令用于显示当前的工作目录,格式为:pwd[选项] @1.查看当前的工作路径: [root@localhost /]# pwd cd 命令用于切换工作路径 格式为:"cd 目录名称& ...

  8. Linux2:vi、ls、cd、pwd、mkdir、rm、mv、cp、cat、tail

    前言 从本篇文章开始,每篇文章将写10个Linux命令,个人的写作想法是: 1.常用的Linux命令,那些生僻的.不常用的就不写了 2.从实际考虑,只列出每个命令常见的用法和参数选项,有兴趣了解进一步 ...

  9. pwd, cd, ls, touch, mkdir, rmdir, rm

    学习Shell命令最好的资料当然的是$man, 绝对是查找命令的第一大杀器,但是我们有时只是想实现某个功能,甚至连这个命令是什么都不知道,又或者不想淹没在man里大段大段的英文里,大家可以参考Linu ...

  10. 每天一个Linux命令(3):pwd命令

    Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文 ...

随机推荐

  1. boost:库program_options--第一篇

    程式執行參數處理函式庫:Boost Program Options(1/N) 一般程式寫得大一點.或是需要比較有彈性,通常都需要在程式執行的時候,從外部讀取一些參數,來做為內部的設定值.一般來說,比較 ...

  2. 理解js的prototype原型对象

    我们创建的每一个函数都有一个prototype(原型)属性.这个属性是一个指针,指向一个对象,而这个对象的用途是包括能够由特定类型的全部实例共享的属性和方法.假设依照字面意思来理解,那么prototy ...

  3. Random Teams

    n participants of the competition were split into m teams in some manner so that each team has at le ...

  4. Python 基础编程

    Python 打印九九乘法表: for i in range(1,10): for j in range(1,i+1): print j,'*',i,'=',j*i,' ', print '\n' P ...

  5. NET 2016

    .NET 2016   阅读目录 初识 .NET 2016 使用 .NET Framework 4.6 编译应用程序 使用 .NET Core CLI 编译应用程序 小结 厚积薄发这个词是高三英语老师 ...

  6. How to configure CDB in Qt Creator(使用VC调试器)

    I was having the same problems too, and finally figured out how to solve this. Styne666 gave me a hi ...

  7. 多文件上传组件FineUploader使用心得

    原文 多文件上传组件FineUploader使用心得 做Web开发的童鞋都知道,需要经常从客户端上传文件到服务端,当然,你可以使用<input type="file"/> ...

  8. 在Android手机上获取其它应用的包名及版本

    转载请注明出处:http://blog.csdn.net/jason_src/article/details/37757661 获取Android手机上其它应用的包名及版本方法有非常多,能够通过AAP ...

  9. C++汉字转拼音(转)

    #include<iostream> #include<string> using namespace std; string findLetter(int nCode); s ...

  10. Python 中的用户自定义类型

    Python中面向对象的技术 Python是面向对象的编程语言,自然提供了面向对象的编程方法.但要给面向对象的编程方法下一个定义,是很困难的.问题关键是理解对象 的含义.对象的含义是广泛的,它是对现实 ...