rewinddir before telldir
xavier Guerin
xavier.guerin@imag.fr
Fri Sep 26 16:24:00 GMT 2008
Hi guys,
I fell on something strange in the implementation of the _seekdir function.
It appears that if you call _seekdir on a particular index without
having called telldir beforehand, the _seekdir function returns (file
telldir.c, line 138) without performing the seek operation. So far so
good, since the index should have been returned by telldir.
However, it's exactly what happens when you use the rewinddir function.
It's not unthinkable to parse a directory with readdir and then rewind
it without calling telldir. It's why (I imagine) rewinddir calls
_seekdir using the arbitrary value 0 as offset.
Wouldn't it be more correct to check for the loc value before returning
(line 138), and in case of 0 call lseek (dir -> dd_fd, 0, 0) ?
Regards,
Xavier
--
Xavier Guérin - Doctoral student
TIMA Laboratory, SLS Group
46, av. Félix Viallet, 38000 GRENOBLE, FR
Mail : xavier.guerin@imag.fr
Phone : +33(0)4 76 57 47 59
Ad Astra Per Aspera
Tristo è quel discepolo che non avanza suo maestro
More information about the Newlib
mailing list