[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] xreadlink.c patch
From: |
Mark D. Baushke |
Subject: |
Re: [Bug-gnulib] xreadlink.c patch |
Date: |
Wed, 03 Nov 2004 08:22:23 -0800 |
Paul Eggert <address@hidden> writes:
> "Mark D. Baushke" <address@hidden> writes:
>
> > It would seem more optimal to put the fix into xmalloc()
>
> I assume you mean "xreadlink()" here?
Yes... it was a typo.
> > because it is already adjusting the size of the buffer it is
> > creating... otherwise, why is xreadlink() not just doing the stat in
> > the first place itself?
>
> Because xreadlink is typically called from places that have already
> done the stat. In coreutils, only one xreadlink call guesses the
> size; the rest already know it.
>
> I'm not particularly worried about optimizing the case for broken
> readlink implementations. They can do a stat twice.
Okay.
> >> xsize.h is somewhat controversial, due to its treatment of overflow.
> >> I'd rather avoid it if it's easy (which is the case here).
> >
> > Hmmm... are those guidelines written anywhere in the documentation yet?
>
> Sorry, no. ("Documentation?" :-)
>
> But after looking at it again, I agree with you that it's less hassle
> for now just to munge xreadlink. I installed this:
>
> 2004-11-03 Paul Eggert <address@hidden>
>
> * xreadlink.c (xreadlink): AIX and HP-UX readlink return -1
> with errno == ERANGE if the buffer is too small.
> Problem reported by Mark D. Baushke.
>
> Index: xreadlink.c
> ===================================================================
> RCS file: /cvsroot/gnulib/gnulib/lib/xreadlink.c,v
> retrieving revision 1.16
> retrieving revision 1.17
> diff -p -u -r1.16 -r1.17
> --- xreadlink.c 2 Nov 2004 20:17:37 -0000 1.16
> +++ xreadlink.c 3 Nov 2004 09:24:17 -0000 1.17
> @@ -66,7 +66,9 @@ xreadlink (char const *filename, size_t
> ssize_t r = readlink (filename, buffer, buf_size);
> size_t link_length = r;
>
> - if (r < 0)
> + /* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1
> + with errno == ERANGE if the buffer is too small. */
> + if (r < 0 && errno != ERANGE)
> {
> int saved_errno = errno;
> free (buffer);
Thank you.
-- Mark
Re: [Bug-gnulib] xreadlink.c patch, Bruno Haible, 2004/11/05