Page 1 of 1

opendir / struct DIR questions

Posted: Sun Feb 07, 2010 5:05 am
by finarfin
hi all,

i'm writing functions for directory handling, but there are some things that i don't understand:
  • First: Which fields struct DIR must contain?
  • Second: opendir/readdir/closedir function need a descriptor table like files? Or is not needed?
For the second question i think no, because if openDir returns a pointer to a DIR structure, there isn't need to have a list of open dirs (i think...).

Thaks to all,
finarfin :)

Re: opendir / struct DIR questions

Posted: Sun Feb 07, 2010 6:19 am
by skyking
DIR (just like FILE) are not mandated to contain any particular field. There may be an association between file descriptor and DIR - you can use fdopendir to open using a open filedescriptor or get the descriptor from a DIR* with dirfd.

This information was gathered by googling for "opendir" (ending up at opengroup).