[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getdelim doesn't set errno on failure?
From: |
Derek Price |
Subject: |
Re: getdelim doesn't set errno on failure? |
Date: |
Wed, 31 Aug 2005 16:17:56 -0400 |
User-agent: |
Mozilla Thunderbird 1.0.6 (Windows/20050716) |
Patch actually attached this time.
Regards,
Derek
Derek Price wrote:
>Oskar Liljeblad wrote:
>
>
>
>>Well, the current Gnulib implementation doesn't behave that way.
>>It will return 0 if the first call to getc fails (for whatever reason -
>>error or EOF). AFAIK, the correct way to test getline/getdelim for
>>
>>
>>
>
>[. . .]
>
>
>
>>I believe the GNU libc documentation needs to be fixed.
>>
>>
>>
>>
>
>Whoa! Why fix the documentation? Why not simply return EOF on EOF, as
>currently described? The attached simple patch fixes this in
>lib/getdelim.c, matching the behavior to that displayed by my local
>glibc. This fix has been tested on at least one platform which was
>prevoiusly looping indefinitely around code that expected (and has
>expected for years) a -1 return to signify EOF.
>
>2005-08-31 Derek Price <address@hidden>
>
> * getdelim.c (getdelim): Return EOF on EOF.
> Reported by Larry Jones <address@hidden>.
>
>Regards,
>
>Derek
>
>
>
--
Derek R. Price
CVS Solutions Architect
Ximbiot <http://ximbiot.com>
v: +1 717.579.6168
f: +1 717.234.3125
<mailto:address@hidden>
Index: lib/getdelim.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getdelim.c,v
retrieving revision 1.1
diff -u -p -r1.1 getdelim.c
--- lib/getdelim.c 2 Aug 2005 09:33:30 -0000 1.1
+++ lib/getdelim.c 31 Aug 2005 17:51:46 -0000
@@ -46,7 +46,7 @@
ssize_t
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
{
- int result;
+ int result = 0;
ssize_t cur_len = 0;
ssize_t len;
@@ -76,7 +76,10 @@ getdelim (char **lineptr, size_t *n, int
i = getc (fp);
if (i == EOF)
+ {
+ result = -1;
break;
+ }
/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n)
@@ -108,7 +111,7 @@ getdelim (char **lineptr, size_t *n, int
break;
}
(*lineptr)[cur_len] = '\0';
- result = cur_len;
+ result = cur_len ? cur_len : result;
unlock_return:
funlockfile (fp);
- Re: getdelim doesn't set errno on failure?, (continued)
- Re: getdelim doesn't set errno on failure?, Oskar Liljeblad, 2005/08/23
- Re: getdelim doesn't set errno on failure?, Bruno Haible, 2005/08/24
- Re: getdelim doesn't set errno on failure?, Jim Meyering, 2005/08/24
- Re: getdelim doesn't set errno on failure?, Bruno Haible, 2005/08/24
- Re: getdelim doesn't set errno on failure?, Oskar Liljeblad, 2005/08/24
- Re: getdelim doesn't set errno on failure?, Jim Meyering, 2005/08/24
- Re: ISO C 99 versus POSIX 2001, Bruno Haible, 2005/08/24
- Re: ISO C 99 versus POSIX 2001, Paul Eggert, 2005/08/24
- Re: getdelim doesn't set errno on failure?, Oskar Liljeblad, 2005/08/24
- Re: getdelim doesn't set errno on failure?, Derek Price, 2005/08/31
- Re: getdelim doesn't set errno on failure?,
Derek Price <=
Re: [bug-gnulib] getdelim doesn't set errno on failure?, Bruno Haible, 2005/08/23