Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jul 2003 13:42:50 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Alexey Neyman <alex.neyman@auriga.ru>
Cc:        hackers@freebsd.org
Subject:   Re: telldir()/seekdir() confusion
Message-ID:  <20030718184250.GC91152@dan.emsphone.com>
In-Reply-To: <200307181637.50764.alex.neyman@auriga.ru>
References:  <20030708192342.GA4899@intarweb.us> <20030708203026.GM87950@dan.emsphone.com> <200307181637.50764.alex.neyman@auriga.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jul 18), Alexey Neyman said:
> hi, there!
> 
> On Wednesday 09 July 2003 00:30, Dan Nelson wrote:
> DN> >     pos = telldir(dirp);
> DN> >     ent = readdir(dirp);
> DN> >     seekdir(dirp, pos);
> DN> >     printf("First telldir:%d\nSecond telldir:%d\n", pos, telldir(dirp));
> 
> DN> I don't think there's any pstandard that says that telldir has to
> DN> return a seekable file offset, or that consecutive calls on the same
> DN> position must return the same value.  Think about a filesystem that
> 
> It seems you're wrong; what follows is a quote from the SUSv3:
> 
> "If the most recent operation on the directory stream was a
> seekdir(), the directory position returned from the telldir() shall
> be the same as that supplied as a loc argument for seekdir()."
> 
> which is clearly violated in this case.
> 
> Also, if I'm not misreading the code, the 'ddloc' structure is freed
> after a successful seekdir() call was made. That said, a value
> returned by the telldir() is rendered invalid after the seekdir() on
> it, and if the seekdir() is called more than once, the 2nd and the
> following calls won't change the stream position. However, I couldn't
> find anything in standard forbidding calling seekdir() twice on the
> same position; the only requirements are using valid position
> (obtained via telldir()) and no calls to rewinddir between telldir()
> and seekdir().

You're right.  I did look at SUSv3 when composing my reply but I
concentrated mostly on the seekdir page and missed that paragraph in
the telldir page.  I'm not sure what the best fix for this should be. 

Maybe only free cookies when closedir() or rewinddir() is called, and
before generating a new cookie, check to see if any existing ones match
your current location?
 
-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030718184250.GC91152>