This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: opendir with empty directory name?


Gary Thomas <gary@mlbassoc.com> writes:

> Hong,Zhichao wrote:
> > Hi, all,
> >  I am wondering what is the behavior of opendir("") in eCos fileio
> > implementation?  I am reading some code written by others.  And the
> > comment says open the current directory then code is written as
> > opendir(""). And the code seems to work as documented.  But should
> > not this actually
> > be opendir(".").  I search the POSIX and various compiler
> > implementation.  It does not seem any of them support this kind of empty
> > directory.  Is this an eCos bug or a feature?
> 
> Why not just use the POSIX standard path (".") and *not*
> rely on [possibly] non-standard behaviour.
> 
> If you've seen other code that uses "" to mean the current
> directory, I'd postulate that code is incorrect or at the
> very least, non portable.  Was this eCos code?  in CVS or
> elsewhere?

While opendir("") is probably non-standard, eCos allows it through by
default as a result of the way that filesystem prefixes are handled.

For example, if a filesystem is mounted on "/fatfs" then
opendir("/fatfs") will cause the filesystem itself to be passed an
empty string after the prefix is stripped off. It is not possible to
distinguish this case from calls to opendir("") in the current
directory -- it's all essentially the same thing.

A more obscure point is that not all filesystems that might be ported
to eCos necessarily implement the "." and ".." pseudo-entries. So it
is useful to have a way to refer to the current directory that doesn't
use them.

As Gary says, for full portability, stick to the POSIX standard naming
conventions.

-- 
Nick Garnett                                      eCos Kernel Architect
eCosCentric Limited    http://www.eCosCentric.com      The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.     Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
**  Visit us at ESC Silicon Valley <http://www.embedded.com/esc/sv>  **
**  April 15-17 2008, Booth 3012, San Jose McEnery Convention Center **


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]