2017-2018-1 20155336 《信息安全系统设计基础》加分作业:实现mypwd
生活随笔
收集整理的這篇文章主要介紹了
2017-2018-1 20155336 《信息安全系统设计基础》加分作业:实现mypwd
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2017-2018-1 20155336 《信息安全系統設計基礎》加分作業:實現mypwd
什么是PWD?
- 用man pwd查看:
- 用于打印當前工作目錄的工作路徑
- 1.命令格式:pwd[選項]
- 2.命令功能:查看”當前工作目錄“的完整路徑
- 3.常用參數: 一般情況下不帶任何參數。如果目錄是鏈接時,格式:pwd -P 顯示出實際路徑,而非使用連接(link)路徑。
實現mypwd
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <string.h> #include <unistd.h> ino_t get_inode(char*); void pwd(ino_t); void name(ino_t,char*,int);int main() {pwd(get_inode(".")); printf("\n");return 0; }void pwd(ino_t this_inode) {ino_t my_inode;char its_name[BUFSIZ];if (get_inode("..")!=this_inode) {chdir(".."); name(this_inode,its_name,BUFSIZ);my_inode = get_inode(".");pwd(my_inode);printf("/%s",its_name);} }void name(ino_t inode,char* namebuf,int buflen) //找到i-節點對應的文件名 {DIR* cdir;struct dirent* direntp;cdir = opendir(".");while((direntp = readdir(cdir)) != NULL){if(direntp->d_ino == inode){strncpy(namebuf,direntp->d_name,buflen);namebuf[buflen-1] = '\0';closedir(cdir);return;}}printf("error looking for inode\n"); }ino_t get_inode(char* fname) //根據文件名,返回-i節點 {struct stat info;stat( fname, &info);return info.st_ino; }測試mypwd
轉載于:https://www.cnblogs.com/hxl681207/p/7995357.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的2017-2018-1 20155336 《信息安全系统设计基础》加分作业:实现mypwd的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: microsoftLanguageExp
- 下一篇: PreparingHomeAssista