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
This commit is contained in:
Pedro F. Giffuni 2016-02-15 18:13:33 +00:00
parent 740be1dc58
commit 2082bf26c8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=295631

View File

@ -37,6 +37,7 @@ static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93";
__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 * __restrict fp)
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);
}