Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Feb 2016 07:48:00 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        "Pedro F. Giffuni" <pfg@freebsd.org>
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:  <20160216073421.B1073@besplex.bde.org>
In-Reply-To: <201602151813.u1FIDXAt067326@repo.freebsd.org>
References:  <201602151813.u1FIDXAt067326@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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.

Bruce



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