Drkcore

04 10 2009 Linux Tweet

Unix/Linuxプログラミング理論と実践 4章 (pwdを書く)

pwdコマンドはinodeを親ディレクトリに辿っていく。ルートディレクトリは. と..が同じinodeを指す。

macbookでls -ia。

$ ls -ia /
      2 ./                                               31452 Users/
      2 ../                                              22730 Volumes/

ので.と..のinodeをチェックしながら再帰的に辿るという実装。

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 );
    }
}

ProductName Unix/Linuxプログラミング理論と実践
Bruce Molay
アスキー・メディアワークス / ¥ 6,090 ()
在庫あり。

ダブル間接ブロックとトリプル間接ブロック

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021