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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"