Why do directory listings contain the current (.) and parent (..) directory?

后端 未结 8 1184
面向向阳花
面向向阳花 2020-12-11 03:11

Whenever I list the contents of a directory with a function like readdir, the returned file names also include \".\" and \"..\". I have the suspicion that these are just nor

8条回答
  •  庸人自扰
    2020-12-11 03:35

    Originally they were hard links, and the number of special cases in the filesystem code for . and .. were minimal. That's not true for all modern filesystems, however.

    But the conventions have been established so that even filesystems where these two directory entries don't actually exist still report their existence through APIs like readdir. Changing this would now would break a lot of code.

提交回复
热议问题