Can telldir() == 0 value be made special?
Nikolaus Rath
Nikolaus at rath.org
Tue Aug 22 18:30:20 UTC 2017
On Aug 22 2017, Conrad Meyer <cem at freebsd.org> wrote:
> Hi Nikolaus,
>
> As you have surmised, DIR* seekpoints are created dynamically whenever
> requested by user's telldir() call:
Good to know, thanks!
> I believe we could special case zero without breaking ABI
> compatibility of correct programs. Something like this:
>
> --- a/lib/libc/gen/telldir.c
> +++ b/lib/libc/gen/telldir.c
> @@ -70,6 +70,20 @@ telldir(DIR *dirp)
> }
> }
> if (lp == NULL) {
> + /* Create special zero telldir entry, similar to Linux */
> + if (dirp->dd_td->td_loccnt == 0 && dirp->dd_loc != 0) {
> + lp = malloc(sizeof(struct ddloc));
> + if (lp == NULL) {
> + if (__isthreaded)
> + _pthread_mutex_unlock(&dirp->dd_lock);
> + return (-1);
> + }
> + lp->loc_index = dirp->dd_td->td_loccnt++;
> + lp->loc_seek = 0;
> + lp->loc_loc = 0;
> + LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe);
> + }
> +
> lp = malloc(sizeof(struct ddloc));
> if (lp == NULL) {
> if (__isthreaded)
>
> I don't know if there are any downsides to special-casing zero like
> this, other than additional code complexity.
This seems a little more complex than I would have expected. Is this
maybe turning zero into a valid argument for seekdir() even if telldir()
has never been called?
That would be even better, but the minimal change that I need is just to
ensure that telldir() either (a) never returns zero, or (b) only returns
zero if called at the beginning of the stream.
Best,
-Nikolaus
--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«
More information about the freebsd-fs
mailing list