Bug 000172

When Created: 08/11/1997 01:00:58
Against DJGPP version: 2.01
By whom:
Abstract: telldir()/seekdir() inconsistency -seekdir(telldir()) doesn't work for rootdirs
I've got a program I'm working on that does some basic directory handling.  I
use the telldir()/seekdir() functions to keep track of where I have been so I
can get back.  When I read a new directory, I skip . and .. if they are
returned, I read an entry, and finally mark the location with telldir() and
close the dir.
	On any SUBDIRECTORY, telldir ends up being 3 after the read of the last
valid entry.  On any ROOT directory, telldir ends up being 1, which would be
understandable since a root directory usually does not contain . and ..  BUT,
readdir() still returns . and .., AND a seekdir to the reported position of "1"
does not place me where I was when I did a telldir(), after the first real file,
but instead places me on ".."
	I'll draw a little table showing a sequence of calls...
		subdir	rootdir
opendir()	  x	   x
readdir()	  .	   .
readdir()	  ..	   ..
readdir()	 file1    file1
telldir()	  3	   1
seekdir(to respective values above)
readdir()	 file2	   ..

As another side note:  telldir() on a root directory returns 0 after reading
either . or ..  On a subdir() it returns 1 and 2 as I suggested earlier.  Also,
I know this is filesystem independent because it happens on both my local HD
and a Netware networked drive.

If anything wasn't clear here or if there are any questions, please e-mail me.
I'll look at the source once I partition my new HD and have room to download it.
Oh, and if it means anything (not that it should), I am cross-compiling from
Linux (running exe on a real dos machine though).

Workaround added: 08/11/1997 01:45:18
By whom:
Here's the workaround I'm implementing:
I don't know when I am im a root directory, but I do know when I am in a subdir.
I count the number of 0 responses telldir() gives after a valid readdir() and
offset all future references in that directory by the count.  Basically, this
should shift telldir's counter up so that it counts the . and .. entries.  This
fix should not conflict with telldir() when it works, since the DJGPP telldir()
counts the entries sequentially (unix usually gives something like inode back),
and should never return 0 after a successful readdir().

Again, I'll look at the libc sources after I have room to download them. :)

Solution added: 04/12/1999 11:00:42
By whom:
This is solved in DJGPP v2.02.

Fixed in version on 04/12/1999 11:00:13
By whom:

  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010