way to make pwd version in C. But not sure how to approach it in C.
The idea is first, call lstat() on “.” to find out the inode number of
the current directory (the “st_ino” member of the struct stat).
Then I change our current directory to the parent directory, with chdir(“..”).
Then I want to read the parent directory with opendir()/readdir()
(using “opendir(“.”)” because we’ve now cd’d there),I am mostly
interested in the d_ino value in the struct returned by readdir(). I am
looking for the original directory in the parent directory. When we find
it, we print its name.
Then call chdir(“..”) again, and repeat until the inode number is 2,
at which point you can print “and then we’re at the root directory” (or
some such similar message).
The idea is great 🙂 Any ideas? Thanks.


0 comments