Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Is readdir ever deterministic?

by ChemBoy (Priest)
on Dec 17, 2001 at 23:54 UTC ( #132636=note: print w/replies, xml ) Need Help??

in reply to Is readdir ever deterministic?

Does there exist a platform where readdir returns . and .. in other than the first two return values?

Yes! Though it took me three months after reading this question to realize it... or possibly something changed in the system setup during those three months. But in any event, I have an example case:

% ls -a ./ ../ 10 11 2 4 5 6 8 9 % perl -le 'opendir DIR, "."; print join " ", readdir DIR' . 2 4 5 6 8 9 .. 10 11

The files were created in the order 2,4,6,8,10,5,9,11 (you could say this was an artificial test case, I suppose...), but this does not seem to affect the sort order. The result is the same running on 5.004/Irix and 5.005/Linux: the key is seems to be the underlying filesystem, which is SGI XFS (under IRIX 6.5).

As a further (and yet more psychotically artificial) test, we have

% touch , % ls -a , ./ ../ 10 11 2 4 5 6 8 9 % perl -le 'opendir DIR, "."; print join " ", readdir DIR' , . 2 4 5 6 8 9 .. 10 11

I haven't done an exhaustive investigation of exactly what XFS does for all cases, but it seems fairly clear that one-character filenames will, in general, break the common assumptions of readdir on that filesystem.

If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://132636]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-06-21 05:41 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.