The entries are probably returned in whatever order the implementor figured would be the fasted order to return them.
Traditionally Unix filesystems store a list files and directories in an unsorted list. Think of it as an array. The fasted way to return the items is to just loop over the array.
A fast way to insert an item into the array is to insert in the next unused slot. Suppose the filesystem does not keep an index that points to the next free slot so the system just loops over the array until it finds a free slot.
A fast way to remove an item is to loop over the array to find the item and then just mark that slot as unused. The system could sort the array when an item is removed but that takes time so it likely just leaves an open slot wherever an item is removed.
There are filesystems (like ReiserFS) that use trees for indexing to give faster searching. In the end the order that items are returned by
readdir is not defined to be sorted in any particular way so it's up to the application to sort the items as required.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.