Re: files "." and ".." from readdir()
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Wed, 16 Jul 2008 22:39:49 -0400
In article <g5m9sh02gif@xxxxxxxxxxxxxxxxx>, phil-news-nospam@xxxxxxxx
wrote:
Will readdir always return "." and ".." as the _first_ two entries returned
if the filesystem has them? I'm just curious if it testing for them can be
skipped after the first two have been tested. I've always written my loops
around readdir with the tests applied in every case.
While most filesystems will probably work this way most of the time,
it's not a good idea to depend on it. It will probably make your loop
more complicated, and the efficiency gained will be negligible on modern
hardware.
It would probably be better to lobby POSIX to create a readdir_nodots()
system call that automatically ignores the "." and ".." entries. A
number of filesystems don't actually have these in the directory, so the
system call has to simulate them on the fly; this call would be simpler,
and many applications (like yours) would happily use it. Although
because it would be new, you'd probably have to maintain the old loop
for a while to be portable to older systems.
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- Follow-Ups:
- Re: files "." and ".." from readdir()
- From: Geoff Clare
- Re: files "." and ".." from readdir()
- References:
- files "." and ".." from readdir()
- From: phil-news-nospam
- files "." and ".." from readdir()
- Prev by Date: files "." and ".." from readdir()
- Next by Date: Re: IPPROTO_RAW
- Previous by thread: files "." and ".." from readdir()
- Next by thread: Re: files "." and ".." from readdir()
- Index(es):
Relevant Pages
|