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') 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 a8c26531339041b2d4aadb7c36bb26448c2208ea Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 15 Feb 2016 18:14:21 +0000 Subject: getln: We cannot expand the buffer beyond INT_MAX. In such cases return ENOMEM. This is a limitation of our implementation, alternatively you may consider getline(3). Differential Revision: https://reviews.freebsd.org/D442 (Partial) Obtained from: Apple Inc. (Libc 997.90.3) Relnotes: yes --- lib/libc/stdio/fgetln.3 | 5 ++++- lib/libc/stdio/fgetln.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fgetln.3 b/lib/libc/stdio/fgetln.3 index 4b83664..7d4b89a5 100644 --- a/lib/libc/stdio/fgetln.3 +++ b/lib/libc/stdio/fgetln.3 @@ -28,7 +28,7 @@ .\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd April 19, 1994 +.Dd February 15, 2016 .Dt FGETLN 3 .Os .Sh NAME @@ -97,6 +97,9 @@ These changes are lost as soon as the pointer becomes invalid. The argument .Fa stream is not a stream open for reading. +.It Bq Er ENOMEM +The internal line buffer could not be expanded due to lack of available memory, +or because it would need to expand beyond INT_MAX in size. .El .Pp The diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c index 1779de2..1509bc8 100644 --- a/lib/libc/stdio/fgetln.c +++ b/lib/libc/stdio/fgetln.c @@ -37,6 +37,8 @@ static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; __FBSDID("$FreeBSD$"); #include "namespace.h" +#include +#include #include #include #include @@ -61,6 +63,10 @@ __slbexpand(FILE *fp, size_t newsize) #endif if (fp->_lb._size >= newsize) return (0); + if (newsize > INT_MAX) { + errno = ENOMEM; + return (-1); + } if ((p = realloc(fp->_lb._base, newsize)) == NULL) return (-1); fp->_lb._base = p; @@ -152,13 +158,14 @@ fgetln(FILE *fp, size_t *lenp) } *lenp = len; #ifdef notdef - fp->_lb._base[len] = 0; + fp->_lb._base[len] = '\0'; #endif FUNLOCKFILE(fp); return ((char *)fp->_lb._base); error: *lenp = 0; /* ??? */ + fp->_flags |= __SERR; FUNLOCKFILE(fp); return (NULL); /* ??? */ } -- 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') 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 From 3e8aeb49a91e40523d3170cbf33224dacff8858b Mon Sep 17 00:00:00 2001 From: bdrewery Date: Wed, 17 Feb 2016 18:41:55 +0000 Subject: Fix build race after r295643. Sponsored by: EMC / Isilon Storage Division --- lib/libc/tests/Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/libc') diff --git a/lib/libc/tests/Makefile b/lib/libc/tests/Makefile index a9d8c02..68ce44c 100644 --- a/lib/libc/tests/Makefile +++ b/lib/libc/tests/Makefile @@ -22,6 +22,8 @@ TESTS_SUBDIRS+= termios TESTS_SUBDIRS+= tls TESTS_SUBDIRS+= ttyio +SUBDIR_DEPEND_tls= tls_dso + .if ${MK_LOCALES} != "no" TESTS_SUBDIRS+= locale .endif -- cgit v1.1 From 647d168b054d82fdb36129bc02d523e9349399b0 Mon Sep 17 00:00:00 2001 From: emaste Date: Thu, 18 Feb 2016 14:17:28 +0000 Subject: Remove dd xfer stats emitted during buildworld They result in gratuitous differences when comparing build log output. --- lib/libc/tests/gen/posix_spawn/Makefile | 2 +- lib/libc/tests/sys/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/tests/gen/posix_spawn/Makefile b/lib/libc/tests/gen/posix_spawn/Makefile index 9bb2cf1..9b687c6 100644 --- a/lib/libc/tests/gen/posix_spawn/Makefile +++ b/lib/libc/tests/gen/posix_spawn/Makefile @@ -20,7 +20,7 @@ CLEANFILES+= h_nonexec .include "../../Makefile.netbsd-tests" h_zero: - dd if=/dev/zero of=h_zero bs=1k count=2 + dd if=/dev/zero of=h_zero bs=1k count=2 status=none chmod a+x h_zero CLEANFILES+= h_zero diff --git a/lib/libc/tests/sys/Makefile b/lib/libc/tests/sys/Makefile index efc892c..c7b0053 100644 --- a/lib/libc/tests/sys/Makefile +++ b/lib/libc/tests/sys/Makefile @@ -78,6 +78,6 @@ truncate_test_FILESGRP= wheel CLEANFILES= truncate_test.root_owned truncate_test.root_owned: - dd if=/dev/null bs=1 count=1 of=${.TARGET} + dd if=/dev/null bs=1 count=1 of=${.TARGET} status=none .include -- cgit v1.1 From 1eb8a7dca663f4ffae7a32384a2f25c6c80df4e5 Mon Sep 17 00:00:00 2001 From: sobomax Date: Thu, 18 Feb 2016 18:41:40 +0000 Subject: Right now, the "virtual hole" API feature of lseek(2) is very vaguely documented and easy to miss. At the same time, it's pretty important for anyone who is trying to use SEEK_HOLE/SEEK_DATA in real app. Try to bridge that gap by making that description more pronounced and also document how it affects failure codes. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D5162 --- lib/libc/sys/lseek.2 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/lseek.2 b/lib/libc/sys/lseek.2 index 349940a..ed75138 100644 --- a/lib/libc/sys/lseek.2 +++ b/lib/libc/sys/lseek.2 @@ -131,8 +131,14 @@ Applications can use .Dv SEEK_HOLE to optimise their behavior for ranges of zeros, but must not depend on it to find all such ranges in a file. +Each file is presented as having a zero-size virtual hole at the very +end of the file. The existence of a hole at the end of every data region allows for easy -programming and implies that a virtual hole exists at the end of the file. +programming and also provides compatibility to the original imlementation +in Solaris. +It also causes the current file size (i.e. end-of-file offset) to be returned +to indicate that there are no more holes past the supplied +.Fa offset . Applications should use .Fn fpathconf _PC_MIN_HOLE_SIZE or @@ -176,9 +182,11 @@ be negative for a non-character special file. For .Dv SEEK_DATA , there are no more data regions past the supplied offset. -For -.Dv SEEK_HOLE , -there are no more holes past the supplied offset. +Due to existence of the hole at the end of the file, for +.Dv SEEK_HOLE +this error is only returned when the +.Fa offset +already points to the end-of-file position. .It Bq Er EOVERFLOW The resulting file offset would be a value which cannot be represented correctly in an object of type -- cgit v1.1 From 3ae05646df771e48ff767b169804fe90db3254a0 Mon Sep 17 00:00:00 2001 From: bjk Date: Thu, 18 Feb 2016 18:50:03 +0000 Subject: Bump .Dd for r295764 Also fix a spelling and grammar nit while here. --- lib/libc/sys/lseek.2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/lseek.2 b/lib/libc/sys/lseek.2 index ed75138..017dc54 100644 --- a/lib/libc/sys/lseek.2 +++ b/lib/libc/sys/lseek.2 @@ -28,7 +28,7 @@ .\" @(#)lseek.2 8.3 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd May 26, 2012 +.Dd February 18, 2016 .Dt LSEEK 2 .Os .Sh NAME @@ -134,9 +134,9 @@ find all such ranges in a file. Each file is presented as having a zero-size virtual hole at the very end of the file. The existence of a hole at the end of every data region allows for easy -programming and also provides compatibility to the original imlementation +programming and also provides compatibility to the original implementation in Solaris. -It also causes the current file size (i.e. end-of-file offset) to be returned +It also causes the current file size (i.e., end-of-file offset) to be returned to indicate that there are no more holes past the supplied .Fa offset . Applications should use -- cgit v1.1 From 1633f2da3e55e2f19f0c0c280026b32fcb9ae708 Mon Sep 17 00:00:00 2001 From: kevlo Date: Fri, 19 Feb 2016 06:50:00 +0000 Subject: Remove sys/types.h --- lib/libc/gen/directory.3 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index f0d0f4b..3919805 100644 --- a/lib/libc/gen/directory.3 +++ b/lib/libc/gen/directory.3 @@ -28,7 +28,7 @@ .\" @(#)directory.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd May 6, 2015 +.Dd February 19, 2016 .Dt DIRECTORY 3 .Os .Sh NAME @@ -46,7 +46,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In dirent.h .Ft DIR * .Fn opendir "const char *filename" -- cgit v1.1