Reputation: 13069
Can any assumption be made on the order of entries in a directory stream obtained with the opendir() function? For example, are .
and ..
always the first two entries? What would cause the order to change?
Upvotes: 2
Views: 277
Reputation: 6266
Posix says that you cannot rely on .
and ..
being the first two entries.
From The Open Group Base Specifications Issue 6:
The directory entries for dot and dot-dot are optional. This volume of IEEE Std 1003.1-2001 does not provide a way to test a priori for their existence because an application that is portable must be written to look for (and usually ignore) those entries. Writing code that presumes that they are the first two entries does not always work, as many implementations permit them to be other than the first two entries, with a "normal" entry preceding them.
Upvotes: 6