From 9e195f526633140954739dd689d6fce887df68dd Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 15 Feb 2016 18:13:33 +0000 Subject: 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 --- lib/libc/stdio/fputs.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/libc/stdio/fputs.c') diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 32e5764..d010979 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include "namespace.h" +#include #include #include #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); } -- cgit v1.1 From 197e3760ab195e2d3b05357e36b2f8857258d71a Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 15 Feb 2016 21:18:52 +0000 Subject: fputs: Return the number of bytes written. Fix r295631: wrong value. Pointy hat: pfg (me) Pointed out by: bde --- lib/libc/stdio/fputs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/libc/stdio/fputs.c') diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index d010979..1f9795a 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -64,6 +64,6 @@ fputs(const char * __restrict s, FILE * __restrict fp) retval = __sfvwrite(fp, &uio); FUNLOCKFILE(fp); if (retval == 0) - return (iov.iov_len > INT_MAX ? INT_MAX : uio.uio_resid); + return (iov.iov_len > INT_MAX ? INT_MAX : iov.iov_len); return (retval); } -- cgit v1.1