Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Feb 2016 16:12:49 -0500
From:      Pedro Giffuni <pfg@FreeBSD.org>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r295631 - head/lib/libc/stdio
Message-ID:  <56C23F51.2070401@FreeBSD.org>
In-Reply-To: <20160216073421.B1073@besplex.bde.org>
References:  <201602151813.u1FIDXAt067326@repo.freebsd.org> <20160216073421.B1073@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help


On 02/15/16 15:48, Bruce Evans wrote:
> On Mon, 15 Feb 2016, Pedro F. Giffuni wrote:
>
>> Log:
>>  fputs: Return the number of bytes written.
>>
>>  POSIX.1-2008 requires that successful completion simply return a
>>  non-negative integer. We have regularly returned a constant value.
>>  Another, equally valid, implementation convention implies returning
>>  the number of bytes written.
>>
>>  Adopt this last convention to be in line with what Apple's libc
>>  does. POSIX also explicitly notes:
>>
>>  Note that this implementation convention cannot be adhered to for
>> strings
>>  longer than {INT_MAX} bytes as the value would not be representable
>> in the
>>  return type of the function. For backwards-compatibility,
>> implementations
>>  can return the number of bytes for strings of up to {INT_MAX} bytes, and
>>  return {INT_MAX} for all longer strings.
>>
>>  Developers shouldn't depend specifically on either convention but
>>  the change may help port software from Apple.
>>
>>  Differential Revision:  https://reviews.freebsd.org/D442 (Partial)
>>  Obtained from:  Apple Inc. (Libc 997.90.3 with changes)
>>  Relnotes:    yes
>>
>> Modified:
>>  head/lib/libc/stdio/fputs.c
>>
>> Modified: head/lib/libc/stdio/fputs.c
>> ==============================================================================
>>
>> --- head/lib/libc/stdio/fputs.c    Mon Feb 15 17:14:10 2016    (r295630)
>> +++ head/lib/libc/stdio/fputs.c    Mon Feb 15 18:13:33 2016    (r295631)
>> @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)fputs.c    8.1
>> __FBSDID("$FreeBSD$");
>>
>> #include "namespace.h"
>> +#include <limits.h>
>> #include <stdio.h>
>> #include <string.h>
>> #include "un-namespace.h"
>> @@ -62,5 +63,7 @@ fputs(const char * __restrict s, FILE *
>>     ORIENT(fp, -1);
>>     retval = __sfvwrite(fp, &uio);
>>     FUNLOCKFILE(fp);
>> +    if (retval == 0)
>> +        return (iov.iov_len > INT_MAX ? INT_MAX : uio.uio_resid);
>>     return (retval);
>> }
>
> Testing would have shown that this change has no effect except in the
> unusual case where iov.iov_len > INT_MAX.  uio.resid is always reduced
> to 0 if all the output actually worked.
>

My mistake, obviously.

It was a last minute change to avoid a cast. Will fix.

Thanks!

Pedro.
> Bruce



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