CVS commit: src/lib/libc/stdio
Module Name:src Committed By: rillig Date: Sat May 4 05:50:49 UTC 2024 Modified Files: src/lib/libc/stdio: mktemp.3 Log Message: mktemp.3: mkdtemp is no longer nonstandard Reported by Aleksey Cheusov on tech-userlevel. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/mktemp.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: rillig Date: Sat May 4 05:50:49 UTC 2024 Modified Files: src/lib/libc/stdio: mktemp.3 Log Message: mktemp.3: mkdtemp is no longer nonstandard Reported by Aleksey Cheusov on tech-userlevel. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/mktemp.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/mktemp.3 diff -u src/lib/libc/stdio/mktemp.3:1.32 src/lib/libc/stdio/mktemp.3:1.33 --- src/lib/libc/stdio/mktemp.3:1.32 Thu Oct 28 09:51:39 2021 +++ src/lib/libc/stdio/mktemp.3 Sat May 4 05:50:49 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: mktemp.3,v 1.32 2021/10/28 09:51:39 kim Exp $ +.\" $NetBSD: mktemp.3,v 1.33 2024/05/04 05:50:49 rillig Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93 .\" -.Dd July 25, 2021 +.Dd May 4, 2024 .Dt MKTEMP 3 .Os .Sh NAME @@ -304,13 +304,12 @@ It was however removed from the specific revision. The .Fn mkstemp -and +function conforms to +.St -p1003.1-2004 . +The .Fn mkdtemp -functions conform to -.St -p1003.1-2004 -and -.St -p1003.1-2008 , -respectively. +function conforms to +.St -p1003.1-2008 . .Sh HISTORY A .Fn mktemp @@ -372,10 +371,6 @@ For this reason, .Xr ld 1 will output a warning message whenever it links code that uses .Fn mktemp . -.Pp -The -.Fn mkdtemp -function is nonstandard and should not be used if portability is required. .Sh SECURITY CONSIDERATIONS The use of .Fn mktemp
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Mar 29 22:39:41 UTC 2024 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: >From enh at google dot com in tech-userlevel. Don't limit writes to BUFSIZ, change the limit to INT_MAX; improves performance dramatically. From: https://github.com/apple-oss-distributions/Libc/commit/\ c5a3293354e22262702a3add5b2dfc9bb0b93b85\ #diff-3b844a19cfb0aab1a23f7fbc457d3bce7453513730c489a72f66ff89d6557ff3 To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Mar 29 22:39:41 UTC 2024 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: >From enh at google dot com in tech-userlevel. Don't limit writes to BUFSIZ, change the limit to INT_MAX; improves performance dramatically. From: https://github.com/apple-oss-distributions/Libc/commit/\ c5a3293354e22262702a3add5b2dfc9bb0b93b85\ #diff-3b844a19cfb0aab1a23f7fbc457d3bce7453513730c489a72f66ff89d6557ff3 To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fvwrite.c diff -u src/lib/libc/stdio/fvwrite.c:1.30 src/lib/libc/stdio/fvwrite.c:1.31 --- src/lib/libc/stdio/fvwrite.c:1.30 Thu Jul 22 13:08:15 2021 +++ src/lib/libc/stdio/fvwrite.c Fri Mar 29 18:39:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.30 2021/07/22 17:08:15 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.31 2024/03/29 22:39:41 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.30 2021/07/22 17:08:15 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.31 2024/03/29 22:39:41 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -99,11 +99,12 @@ __sfvwrite(FILE *fp, struct __suio *uio) } if (fp->_flags & __SNBF) { /* - * Unbuffered: write up to BUFSIZ bytes at a time. + * Unbuffered: write up to INT_MAX bytes at a time, to not + * truncate the value of len if it is greater than 2^31 bytes. */ do { GETIOV(;); - w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); + w = (*fp->_write)(fp->_cookie, p, MIN(len, INT_MAX)); if (w <= 0) goto err; p += w; @@ -113,7 +114,8 @@ __sfvwrite(FILE *fp, struct __suio *uio) /* * Fully buffered: fill partially full buffer, if any, * and then flush. If there is no partial buffer, write - * one _bf._size byte chunk directly (without copying). + * entire payload directly (without copying) up to a multiple + * of the buffer size. * * String output is a special case: write as many bytes * as fit, but pretend we wrote everything. This makes @@ -159,7 +161,15 @@ __sfvwrite(FILE *fp, struct __suio *uio) if (fflush(fp)) goto err; } else if (len >= (size_t)(w = fp->_bf._size)) { -/* write directly */ +/* + * write directly up to INT_MAX or greatest + * multiple of buffer size (whatever is + * smaller), keeping in the memory buffer the + * remaining part of payload that is smaller + * than buffer size. + */ +if (w != 0) + w = MIN(w * (len / w), INT_MAX); w = (*fp->_write)(fp->_cookie, p, (size_t)w); if (w <= 0) goto err;
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Sun Apr 3 14:17:53 UTC 2022 Modified Files: src/lib/libc/stdio: printf.3 Log Message: Improve wording to avoid confusion about the return value of {v,}asprintf(3) To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/lib/libc/stdio/printf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/printf.3 diff -u src/lib/libc/stdio/printf.3:1.70 src/lib/libc/stdio/printf.3:1.71 --- src/lib/libc/stdio/printf.3:1.70 Thu Sep 23 08:17:57 2021 +++ src/lib/libc/stdio/printf.3 Sun Apr 3 10:17:53 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: printf.3,v 1.70 2021/09/23 12:17:57 wiz Exp $ +.\" $NetBSD: printf.3,v 1.71 2022/04/03 14:17:53 christos Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 .\" -.Dd November 19, 2015 +.Dd April 3, 2022 .Dt PRINTF 3 .Os .Sh NAME @@ -141,11 +141,11 @@ floating point formats, positional argum .Fn asprintf and .Fn vasprintf -return a pointer to a buffer sufficiently large to hold the -string in the -.Fa ret -argument. -This pointer should be passed to +set the +.Fa ret +argument to a pointer containing the formatted string. +This pointer +points to a newly allocated buffer and should be passed to .Xr free 3 to release the allocated storage when it is no longer needed. If sufficient space cannot be allocated, these functions
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Sun Apr 3 14:17:53 UTC 2022 Modified Files: src/lib/libc/stdio: printf.3 Log Message: Improve wording to avoid confusion about the return value of {v,}asprintf(3) To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/lib/libc/stdio/printf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: nia Date: Sat Mar 12 08:36:52 UTC 2022 Modified Files: src/lib/libc/stdio: vfwprintf.c Log Message: vfwprintf(3): use reallocarr To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/lib/libc/stdio/vfwprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/vfwprintf.c diff -u src/lib/libc/stdio/vfwprintf.c:1.36 src/lib/libc/stdio/vfwprintf.c:1.37 --- src/lib/libc/stdio/vfwprintf.c:1.36 Tue Jul 11 19:36:38 2017 +++ src/lib/libc/stdio/vfwprintf.c Sat Mar 12 08:36:52 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: vfwprintf.c,v 1.36 2017/07/11 19:36:38 perseant Exp $ */ +/* $NetBSD: vfwprintf.c,v 1.37 2022/03/12 08:36:52 nia Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $"); #else -__RCSID("$NetBSD: vfwprintf.c,v 1.36 2017/07/11 19:36:38 perseant Exp $"); +__RCSID("$NetBSD: vfwprintf.c,v 1.37 2022/03/12 08:36:52 nia Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -459,9 +459,11 @@ __mbsconv(char *mbsarg, int prec, locale * converting at most `size' bytes of the input multibyte string to * wide characters for printing. */ - convbuf = malloc((insize + 1) * sizeof(*convbuf)); - if (convbuf == NULL) + convbuf = NULL; + if (reallocarr(, insize + 1, sizeof(*convbuf)) != 0) { + errno = ENOMEM; return NULL; + } wcp = convbuf; p = mbsarg; mbs = initial; @@ -1976,12 +1978,16 @@ __grow_type_table (size_t nextarg, enum if (newsize < nextarg + 1) newsize = nextarg + 1; if (oldsize == STATIC_ARG_TBL_SIZE) { - if ((newtable = malloc(newsize * sizeof(*newtable))) == NULL) + newtable = NULL; + if (reallocarr(, newsize, sizeof(*newtable)) != 0) { + errno = ENOMEM; return -1; + } memcpy(newtable, oldtable, oldsize * sizeof(*newtable)); } else { - newtable = realloc(oldtable, newsize * sizeof(*newtable)); - if (newtable == NULL) { + newtable = oldtable; + if (reallocarr(, newsize, sizeof(*newtable)) != 0) { + errno = ENOMEM; free(oldtable); return -1; }
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: nia Date: Sat Mar 12 08:36:52 UTC 2022 Modified Files: src/lib/libc/stdio: vfwprintf.c Log Message: vfwprintf(3): use reallocarr To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/lib/libc/stdio/vfwprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kim Date: Thu Oct 28 09:51:39 UTC 2021 Modified Files: src/lib/libc/stdio: mktemp.3 Log Message: Use .Sq instead of a dangling .So To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdio/mktemp.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kim Date: Thu Oct 28 09:51:39 UTC 2021 Modified Files: src/lib/libc/stdio: mktemp.3 Log Message: Use .Sq instead of a dangling .So To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdio/mktemp.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/mktemp.3 diff -u src/lib/libc/stdio/mktemp.3:1.31 src/lib/libc/stdio/mktemp.3:1.32 --- src/lib/libc/stdio/mktemp.3:1.31 Sun Jul 25 08:52:03 2021 +++ src/lib/libc/stdio/mktemp.3 Thu Oct 28 09:51:39 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: mktemp.3,v 1.31 2021/07/25 08:52:03 simonb Exp $ +.\" $NetBSD: mktemp.3,v 1.32 2021/10/28 09:51:39 kim Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -66,24 +66,24 @@ to create a file name. This file name is unique and suitable for use by the application. The template may be any file name with some number of -.So Li X +.Sq Li X characters appended to it, for example .Pa /tmp/temp.XX . The trailing -.So Li X +.Sq Li X characters in the template are replaced with a unique letter and number combination. .Fn mktemp can return depends on the number of -.So Li X +.Sq Li X characters provided. Although the .Nx implementation of the functions will accept any number of trailing -.So Li X +.Sq Li X characters, for portability reasons one should use only six. Using six -.So Li X +.Sq Li X characters will result in .Fn mktemp testing roughly 62 ** 6 (56800235584) combinations.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Thu Sep 23 12:17:57 UTC 2021 Modified Files: src/lib/libc/stdio: printf.3 Log Message: printf(3): mention snprintb(3) To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/lib/libc/stdio/printf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/printf.3 diff -u src/lib/libc/stdio/printf.3:1.69 src/lib/libc/stdio/printf.3:1.70 --- src/lib/libc/stdio/printf.3:1.69 Tue Feb 16 14:44:25 2021 +++ src/lib/libc/stdio/printf.3 Thu Sep 23 12:17:57 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: printf.3,v 1.69 2021/02/16 14:44:25 riastradh Exp $ +.\" $NetBSD: printf.3,v 1.70 2021/09/23 12:17:57 wiz Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -811,6 +811,7 @@ or the return value would be too large t .Xr fmtcheck 3 , .Xr scanf 3 , .Xr setlocale 3 , +.Xr snprintb 3 , .Xr wprintf 3 , .Xr printf 9 .Sh STANDARDS
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Thu Sep 23 12:17:57 UTC 2021 Modified Files: src/lib/libc/stdio: printf.3 Log Message: printf(3): mention snprintb(3) To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/lib/libc/stdio/printf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: rillig Date: Sat Sep 11 18:46:22 UTC 2021 Modified Files: src/lib/libc/stdio: fseek.3 Log Message: fseek.3: fix grammar To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdio/fseek.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fseek.3 diff -u src/lib/libc/stdio/fseek.3:1.28 src/lib/libc/stdio/fseek.3:1.29 --- src/lib/libc/stdio/fseek.3:1.28 Sun Jan 1 12:39:33 2017 +++ src/lib/libc/stdio/fseek.3 Sat Sep 11 18:46:22 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: fseek.3,v 1.28 2017/01/01 12:39:33 abhinav Exp $ +.\" $NetBSD: fseek.3,v 1.29 2021/09/11 18:46:22 rillig Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 .\" -.Dd January 1, 2017 +.Dd September 11, 2021 .Dt FSEEK 3 .Os .Sh NAME @@ -130,7 +130,7 @@ except that the error indicator for the In this implementations, .Dq Fa fpos_t is a complex object that represents both the position and the parse -state of the stream, making these routines as the only way to portably +state of the stream, making these routines the only way to portably reposition a text stream. The .Ar pos
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: rillig Date: Sat Sep 11 18:46:22 UTC 2021 Modified Files: src/lib/libc/stdio: fseek.3 Log Message: fseek.3: fix grammar To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdio/fseek.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 22 17:09:01 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: revert changes to fflush.c (1.18) and fvwrite.c (1.25) until we investigate collateral damage. Breaks h_intr.c test. Requested by RVP. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.c diff -u src/lib/libc/stdio/fflush.c:1.23 src/lib/libc/stdio/fflush.c:1.24 --- src/lib/libc/stdio/fflush.c:1.23 Fri Jul 9 05:24:16 2021 +++ src/lib/libc/stdio/fflush.c Thu Jul 22 13:09:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.23 2021/07/09 09:24:16 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.24 2021/07/22 17:09:01 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.23 2021/07/09 09:24:16 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.24 2021/07/22 17:09:01 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,8 +45,6 @@ __RCSID("$NetBSD: fflush.c,v 1.23 2021/0 #include #include #include -#include - #include "reentrant.h" #include "local.h" @@ -107,18 +105,7 @@ __sflush(FILE *fp) for (; n > 0; n -= t, p += t) { t = (*fp->_write)(fp->_cookie, (char *)p, n); - if (t == 0) - goto out; - if (t < 0) { - /* Reset _p and _w. */ - if (p > fp->_p) { -/* Some was written. */ -memmove(fp->_p, p, n); - } - fp->_p += n; - if ((fp->_flags & (__SLBF | __SNBF)) == 0) -fp->_w -= n; -out: + if (t <= 0) { fp->_flags |= __SERR; return EOF; }
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 22 17:09:01 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: revert changes to fflush.c (1.18) and fvwrite.c (1.25) until we investigate collateral damage. Breaks h_intr.c test. Requested by RVP. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 22 17:08:15 UTC 2021 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: revert changes to fflush.c (1.18) and fvwrite.c (1.25) until we investigate collateral damage. Breaks h_intr.c test. Requested by RVP. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fvwrite.c diff -u src/lib/libc/stdio/fvwrite.c:1.29 src/lib/libc/stdio/fvwrite.c:1.30 --- src/lib/libc/stdio/fvwrite.c:1.29 Mon Jul 19 06:00:32 2021 +++ src/lib/libc/stdio/fvwrite.c Thu Jul 22 13:08:15 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.29 2021/07/19 10:00:32 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.30 2021/07/22 17:08:15 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.29 2021/07/19 10:00:32 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.30 2021/07/22 17:08:15 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,39 +51,6 @@ __RCSID("$NetBSD: fvwrite.c,v 1.29 2021/ #include "local.h" #include "fvwrite.h" -static int -flush_adj(FILE *fp, struct __suio *uio, ssize_t w) -{ - int rc; - - _DIAGASSERT(w >= 0); - _DIAGASSERT(fp->_w >= 0); - - if ((rc = fflush(fp)) == 0) - return 0; - - /* - * If we have to return without writing the whole buffer, - * adjust for how much fflush() has written for us. - * `w' is the amt. of new user data just copied into our - * internal buffer in _this_ fwrite() call. - */ - if (fp->_w < w) { - /* some new data was also written */ - ssize_t i = w - fp->_w; - - /* adjust amt. written */ - uio->uio_resid -= i; - } else { - /* only old stuff was written */ - - /* adjust _p and _w so user can retry */ - fp->_p -= w; - fp->_w += w; - } - return rc; -} - /* * Write some memory regions. Return zero on success, EOF on error. * @@ -130,21 +97,15 @@ __sfvwrite(FILE *fp, struct __suio *uio) len = iov->iov_len; \ iov++; \ } -#define WRITE(nw) \ - w = (*fp->_write)(fp->_cookie, p, nw); \ - if (w <= 0) \ - goto err -#define FLUSH(nw) \ - if (flush_adj(fp, uio, nw)) \ - goto err - if (fp->_flags & __SNBF) { /* * Unbuffered: write up to BUFSIZ bytes at a time. */ do { GETIOV(;); - WRITE(MIN(len, BUFSIZ)); + w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); + if (w <= 0) +goto err; p += w; len -= w; } while ((uio->uio_resid -= w) != 0); @@ -195,10 +156,13 @@ __sfvwrite(FILE *fp, struct __suio *uio) COPY(w); /* fp->_w -= w; */ /* unneeded */ fp->_p += w; -FLUSH(w); +if (fflush(fp)) + goto err; } else if (len >= (size_t)(w = fp->_bf._size)) { /* write directly */ -WRITE((size_t)w); +w = (*fp->_write)(fp->_cookie, p, (size_t)w); +if (w <= 0) + goto err; } else { /* fill and done */ w = len; @@ -232,9 +196,12 @@ __sfvwrite(FILE *fp, struct __suio *uio) COPY(w); /* fp->_w -= w; */ fp->_p += w; -FLUSH(w); +if (fflush(fp)) + goto err; } else if (s >= (w = fp->_bf._size)) { -WRITE((size_t)w); +w = (*fp->_write)(fp->_cookie, p, (size_t)w); +if (w <= 0) + goto err; } else { w = s; COPY(w); @@ -243,7 +210,8 @@ __sfvwrite(FILE *fp, struct __suio *uio) } if ((nldist -= w) == 0) { /* copied the newline: flush and forget */ -FLUSH(w); +if (fflush(fp)) + goto err; nlknown = 0; } p += w;
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 22 17:08:15 UTC 2021 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: revert changes to fflush.c (1.18) and fvwrite.c (1.25) until we investigate collateral damage. Breaks h_intr.c test. Requested by RVP. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Mon Jul 19 10:00:33 UTC 2021 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: There's no need to adjust `iov' in the error path. Returning the amount written is all that's needed. from RVP To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fvwrite.c diff -u src/lib/libc/stdio/fvwrite.c:1.28 src/lib/libc/stdio/fvwrite.c:1.29 --- src/lib/libc/stdio/fvwrite.c:1.28 Fri Jul 16 08:34:10 2021 +++ src/lib/libc/stdio/fvwrite.c Mon Jul 19 06:00:32 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.28 2021/07/16 12:34:10 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.29 2021/07/19 10:00:32 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.28 2021/07/16 12:34:10 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.29 2021/07/19 10:00:32 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,7 +52,7 @@ __RCSID("$NetBSD: fvwrite.c,v 1.28 2021/ #include "fvwrite.h" static int -flush_adj(FILE *fp, struct __suio *uio, struct __siov *iov, ssize_t w) +flush_adj(FILE *fp, struct __suio *uio, ssize_t w) { int rc; @@ -74,7 +74,6 @@ flush_adj(FILE *fp, struct __suio *uio, /* adjust amt. written */ uio->uio_resid -= i; - iov->iov_len -= i; } else { /* only old stuff was written */ @@ -136,7 +135,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) if (w <= 0) \ goto err #define FLUSH(nw) \ - if (flush_adj(fp, uio, iov - 1, nw)) \ + if (flush_adj(fp, uio, nw)) \ goto err if (fp->_flags & __SNBF) {
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Mon Jul 19 10:00:33 UTC 2021 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: There's no need to adjust `iov' in the error path. Returning the amount written is all that's needed. from RVP To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Jul 16 12:34:10 UTC 2021 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: When fflush fails, adjust pointers and the io vectors. From RVP. Fixes core-dump at cvs(1) exit(3). To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fvwrite.c diff -u src/lib/libc/stdio/fvwrite.c:1.27 src/lib/libc/stdio/fvwrite.c:1.28 --- src/lib/libc/stdio/fvwrite.c:1.27 Thu Jul 8 05:06:51 2021 +++ src/lib/libc/stdio/fvwrite.c Fri Jul 16 08:34:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.27 2021/07/08 09:06:51 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.28 2021/07/16 12:34:10 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.27 2021/07/08 09:06:51 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.28 2021/07/16 12:34:10 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,6 +51,40 @@ __RCSID("$NetBSD: fvwrite.c,v 1.27 2021/ #include "local.h" #include "fvwrite.h" +static int +flush_adj(FILE *fp, struct __suio *uio, struct __siov *iov, ssize_t w) +{ + int rc; + + _DIAGASSERT(w >= 0); + _DIAGASSERT(fp->_w >= 0); + + if ((rc = fflush(fp)) == 0) + return 0; + + /* + * If we have to return without writing the whole buffer, + * adjust for how much fflush() has written for us. + * `w' is the amt. of new user data just copied into our + * internal buffer in _this_ fwrite() call. + */ + if (fp->_w < w) { + /* some new data was also written */ + ssize_t i = w - fp->_w; + + /* adjust amt. written */ + uio->uio_resid -= i; + iov->iov_len -= i; + } else { + /* only old stuff was written */ + + /* adjust _p and _w so user can retry */ + fp->_p -= w; + fp->_w += w; + } + return rc; +} + /* * Write some memory regions. Return zero on success, EOF on error. * @@ -102,10 +136,8 @@ __sfvwrite(FILE *fp, struct __suio *uio) if (w <= 0) \ goto err #define FLUSH(nw) \ - if (fflush(fp)) { \ - fp->_p -= nw; /* rewind unwritten */ \ - goto err; \ - } + if (flush_adj(fp, uio, iov - 1, nw)) \ + goto err if (fp->_flags & __SNBF) { /*
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Jul 16 12:34:10 UTC 2021 Modified Files: src/lib/libc/stdio: fvwrite.c Log Message: When fflush fails, adjust pointers and the io vectors. From RVP. Fixes core-dump at cvs(1) exit(3). To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Jul 9 09:24:16 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: Don't adjust the buffers when write returns 0. This happens with fmemopen and other synthetic write functions. This fixes the unit-tests for fmemopen, but adjusting should be the right behavior for all cases? To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.c diff -u src/lib/libc/stdio/fflush.c:1.22 src/lib/libc/stdio/fflush.c:1.23 --- src/lib/libc/stdio/fflush.c:1.22 Thu Jul 8 11:44:44 2021 +++ src/lib/libc/stdio/fflush.c Fri Jul 9 05:24:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.22 2021/07/08 15:44:44 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.23 2021/07/09 09:24:16 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.22 2021/07/08 15:44:44 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.23 2021/07/09 09:24:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -107,7 +107,9 @@ __sflush(FILE *fp) for (; n > 0; n -= t, p += t) { t = (*fp->_write)(fp->_cookie, (char *)p, n); - if (t <= 0) { + if (t == 0) + goto out; + if (t < 0) { /* Reset _p and _w. */ if (p > fp->_p) { /* Some was written. */ @@ -116,6 +118,7 @@ __sflush(FILE *fp) fp->_p += n; if ((fp->_flags & (__SLBF | __SNBF)) == 0) fp->_w -= n; +out: fp->_flags |= __SERR; return EOF; }
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Jul 9 09:24:16 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: Don't adjust the buffers when write returns 0. This happens with fmemopen and other synthetic write functions. This fixes the unit-tests for fmemopen, but adjusting should be the right behavior for all cases? To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 8 15:44:44 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: Include the 0 return from write. Although the real write system call does not return 0, the synthetic writes from funopen/fmemopen could. This avoids infinite loops in >= test19 in fmemopen, but the tests still fail, perhaps because they assume the previous behavior, where flush does not adjust the stdio pointers on error. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 8 15:44:44 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: Include the 0 return from write. Although the real write system call does not return 0, the synthetic writes from funopen/fmemopen could. This avoids infinite loops in >= test19 in fmemopen, but the tests still fail, perhaps because they assume the previous behavior, where flush does not adjust the stdio pointers on error. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.c diff -u src/lib/libc/stdio/fflush.c:1.21 src/lib/libc/stdio/fflush.c:1.22 --- src/lib/libc/stdio/fflush.c:1.21 Thu Jul 8 05:06:51 2021 +++ src/lib/libc/stdio/fflush.c Thu Jul 8 11:44:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.21 2021/07/08 09:06:51 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.22 2021/07/08 15:44:44 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.21 2021/07/08 09:06:51 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.22 2021/07/08 15:44:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -107,7 +107,7 @@ __sflush(FILE *fp) for (; n > 0; n -= t, p += t) { t = (*fp->_write)(fp->_cookie, (char *)p, n); - if (t < 0) { + if (t <= 0) { /* Reset _p and _w. */ if (p > fp->_p) { /* Some was written. */
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 8 09:06:51 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c fvwrite.c Log Message: Obey EINTR and return immediately adjusting for unwritten. From RVP To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdio/fflush.c cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Thu Jul 8 09:06:51 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c fvwrite.c Log Message: Obey EINTR and return immediately adjusting for unwritten. From RVP To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdio/fflush.c cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.c diff -u src/lib/libc/stdio/fflush.c:1.20 src/lib/libc/stdio/fflush.c:1.21 --- src/lib/libc/stdio/fflush.c:1.20 Tue Jul 6 10:22:16 2021 +++ src/lib/libc/stdio/fflush.c Thu Jul 8 05:06:51 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.20 2021/07/06 14:22:16 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.21 2021/07/08 09:06:51 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.20 2021/07/06 14:22:16 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.21 2021/07/08 09:06:51 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -108,18 +108,14 @@ __sflush(FILE *fp) for (; n > 0; n -= t, p += t) { t = (*fp->_write)(fp->_cookie, (char *)p, n); if (t < 0) { - if (errno == EINTR) { -t = 0; -continue; - } /* Reset _p and _w. */ if (p > fp->_p) { /* Some was written. */ memmove(fp->_p, p, n); -fp->_p += n; -if ((fp->_flags & (__SLBF | __SNBF)) == 0) - fp->_w -= n; } + fp->_p += n; + if ((fp->_flags & (__SLBF | __SNBF)) == 0) +fp->_w -= n; fp->_flags |= __SERR; return EOF; } Index: src/lib/libc/stdio/fvwrite.c diff -u src/lib/libc/stdio/fvwrite.c:1.26 src/lib/libc/stdio/fvwrite.c:1.27 --- src/lib/libc/stdio/fvwrite.c:1.26 Tue Jul 6 10:22:16 2021 +++ src/lib/libc/stdio/fvwrite.c Thu Jul 8 05:06:51 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.26 2021/07/06 14:22:16 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.27 2021/07/08 09:06:51 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.26 2021/07/06 14:22:16 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.27 2021/07/08 09:06:51 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -99,12 +99,14 @@ __sfvwrite(FILE *fp, struct __suio *uio) } #define WRITE(nw) \ w = (*fp->_write)(fp->_cookie, p, nw); \ - if (w < 0) { \ - if (errno != EINTR) \ - goto err; \ - w = 0; \ - } else \ - w = w + if (w <= 0) \ + goto err +#define FLUSH(nw) \ + if (fflush(fp)) { \ + fp->_p -= nw; /* rewind unwritten */ \ + goto err; \ + } + if (fp->_flags & __SNBF) { /* * Unbuffered: write up to BUFSIZ bytes at a time. @@ -162,8 +164,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) COPY(w); /* fp->_w -= w; */ /* unneeded */ fp->_p += w; -if (fflush(fp)) - goto err; +FLUSH(w); } else if (len >= (size_t)(w = fp->_bf._size)) { /* write directly */ WRITE((size_t)w); @@ -200,8 +201,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) COPY(w); /* fp->_w -= w; */ fp->_p += w; -if (fflush(fp)) - goto err; +FLUSH(w); } else if (s >= (w = fp->_bf._size)) { WRITE((size_t)w); } else { @@ -212,8 +212,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) } if ((nldist -= w) == 0) { /* copied the newline: flush and forget */ -if (fflush(fp)) - goto err; +FLUSH(w); nlknown = 0; } p += w;
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Tue Jul 6 14:22:16 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c fvwrite.c Log Message: Handle EINTR, from RVP. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdio/fflush.c cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Tue Jul 6 14:22:16 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c fvwrite.c Log Message: Handle EINTR, from RVP. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdio/fflush.c cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdio/fvwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.c diff -u src/lib/libc/stdio/fflush.c:1.19 src/lib/libc/stdio/fflush.c:1.20 --- src/lib/libc/stdio/fflush.c:1.19 Mon Jul 5 03:26:00 2021 +++ src/lib/libc/stdio/fflush.c Tue Jul 6 10:22:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.19 2021/07/05 07:26:00 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.20 2021/07/06 14:22:16 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.19 2021/07/05 07:26:00 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.20 2021/07/06 14:22:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -107,7 +107,11 @@ __sflush(FILE *fp) for (; n > 0; n -= t, p += t) { t = (*fp->_write)(fp->_cookie, (char *)p, n); - if (t <= 0) { + if (t < 0) { + if (errno == EINTR) { +t = 0; +continue; + } /* Reset _p and _w. */ if (p > fp->_p) { /* Some was written. */ Index: src/lib/libc/stdio/fvwrite.c diff -u src/lib/libc/stdio/fvwrite.c:1.25 src/lib/libc/stdio/fvwrite.c:1.26 --- src/lib/libc/stdio/fvwrite.c:1.25 Tue Mar 27 11:05:42 2012 +++ src/lib/libc/stdio/fvwrite.c Tue Jul 6 10:22:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.25 2012/03/27 15:05:42 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.26 2021/07/06 14:22:16 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.25 2012/03/27 15:05:42 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.26 2021/07/06 14:22:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -97,15 +97,21 @@ __sfvwrite(FILE *fp, struct __suio *uio) len = iov->iov_len; \ iov++; \ } +#define WRITE(nw) \ + w = (*fp->_write)(fp->_cookie, p, nw); \ + if (w < 0) { \ + if (errno != EINTR) \ + goto err; \ + w = 0; \ + } else \ + w = w if (fp->_flags & __SNBF) { /* * Unbuffered: write up to BUFSIZ bytes at a time. */ do { GETIOV(;); - w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); - if (w <= 0) -goto err; + WRITE(MIN(len, BUFSIZ)); p += w; len -= w; } while ((uio->uio_resid -= w) != 0); @@ -160,9 +166,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) goto err; } else if (len >= (size_t)(w = fp->_bf._size)) { /* write directly */ -w = (*fp->_write)(fp->_cookie, p, (size_t)w); -if (w <= 0) - goto err; +WRITE((size_t)w); } else { /* fill and done */ w = len; @@ -199,9 +203,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) if (fflush(fp)) goto err; } else if (s >= (w = fp->_bf._size)) { -w = (*fp->_write)(fp->_cookie, p, (size_t)w); -if (w <= 0) - goto err; +WRITE((size_t)w); } else { w = s; COPY(w);
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Mon Jul 5 07:26:00 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: Account for partial writes when interrupted (from FreeBSD). To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.c diff -u src/lib/libc/stdio/fflush.c:1.18 src/lib/libc/stdio/fflush.c:1.19 --- src/lib/libc/stdio/fflush.c:1.18 Tue Mar 27 11:05:42 2012 +++ src/lib/libc/stdio/fflush.c Mon Jul 5 03:26:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.19 2021/07/05 07:26:00 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.19 2021/07/05 07:26:00 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,6 +45,8 @@ __RCSID("$NetBSD: fflush.c,v 1.18 2012/0 #include #include #include +#include + #include "reentrant.h" #include "local.h" @@ -106,6 +108,14 @@ __sflush(FILE *fp) for (; n > 0; n -= t, p += t) { t = (*fp->_write)(fp->_cookie, (char *)p, n); if (t <= 0) { + /* Reset _p and _w. */ + if (p > fp->_p) { +/* Some was written. */ +memmove(fp->_p, p, n); +fp->_p += n; +if ((fp->_flags & (__SLBF | __SNBF)) == 0) + fp->_w -= n; + } fp->_flags |= __SERR; return EOF; }
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Mon Jul 5 07:26:00 UTC 2021 Modified Files: src/lib/libc/stdio: fflush.c Log Message: Account for partial writes when interrupted (from FreeBSD). To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/fflush.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: jdolecek Date: Sun Feb 7 15:54:09 UTC 2021 Modified Files: src/lib/libc/stdio: fread.c Log Message: restore change from rev 1.23 "Avoid undefined behavior in fread(3)", mistakely removed as part __SNBF optimization To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdio/fread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: jdolecek Date: Sun Feb 7 15:54:09 UTC 2021 Modified Files: src/lib/libc/stdio: fread.c Log Message: restore change from rev 1.23 "Avoid undefined behavior in fread(3)", mistakely removed as part __SNBF optimization To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdio/fread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fread.c diff -u src/lib/libc/stdio/fread.c:1.25 src/lib/libc/stdio/fread.c:1.26 --- src/lib/libc/stdio/fread.c:1.25 Mon Feb 1 17:50:53 2021 +++ src/lib/libc/stdio/fread.c Sun Feb 7 15:54:09 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fread.c,v 1.25 2021/02/01 17:50:53 jdolecek Exp $ */ +/* $NetBSD: fread.c,v 1.26 2021/02/07 15:54:09 jdolecek Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #else -__RCSID("$NetBSD: fread.c,v 1.25 2021/02/01 17:50:53 jdolecek Exp $"); +__RCSID("$NetBSD: fread.c,v 1.26 2021/02/07 15:54:09 jdolecek Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -81,8 +81,6 @@ fread(void *buf, size_t size, size_t cou _DIAGASSERT(buf != NULL); FLOCKFILE(fp); - if (fp->_r < 0) - fp->_r = 0; total = resid; p = buf; @@ -115,12 +113,18 @@ fread(void *buf, size_t size, size_t cou return (count); } + if (fp->_r <= 0) { + /* Nothing to read on enter, refill the buffers. */ + goto refill; + } + while (resid > (size_t)(r = fp->_r)) { (void)memcpy(p, fp->_p, (size_t)r); fp->_p += r; /* fp->_r = 0 ... done in __srefill */ p += r; resid -= r; +refill: if (__srefill(fp)) { /* no more input: return partial result */ FUNLOCKFILE(fp);
Re: CVS commit: src/lib/libc/stdio
Date:Mon, 1 Feb 2021 17:50:54 + From:"Jaromir Dolecek" Message-ID: <20210201175054.112e7f...@cvs.netbsd.org> | FreeBSD has a similar check, but they return EINVAL instead, feel | free to adjust if SUS or other standard mandates specific value Not currently (unless the C standard says something) - but EINVAL would be a better choice, fread() incorporates all errors from fgetc() (and fwrite() from fputc()) and there EOVERFLOW is used to indicate that the file offset exceeds the maximum possible file size, which is quite a different problem. EINVAL is currently unused (at least in POSIX) but makes more sense for this problem (which is am invalid arg combination). FWIW, I submitted a defect report on this issue with the Austin Group (POSIX maintainers) yesterday, though I am expecting they'll simply punt it to the C standards group. kre
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: jdolecek Date: Mon Feb 1 17:50:53 UTC 2021 Modified Files: src/lib/libc/stdio: fread.3 fread.c fwrite.c Log Message: for fread(3) and fwrite(3) check for (size * nmemb) size_t overflow, and error out with EOVERFLOW if it happens; this is less silly answer to a silly call than returning some randomly wrapped length change adapted from OpenBSD FreeBSD has a similar check, but they return EINVAL instead, feel free to adjust if SUS or other standard mandates specific value suggested by Kamil Rytarowski To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fread.3 cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdio/fread.c cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/fwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: jdolecek Date: Mon Feb 1 17:50:53 UTC 2021 Modified Files: src/lib/libc/stdio: fread.3 fread.c fwrite.c Log Message: for fread(3) and fwrite(3) check for (size * nmemb) size_t overflow, and error out with EOVERFLOW if it happens; this is less silly answer to a silly call than returning some randomly wrapped length change adapted from OpenBSD FreeBSD has a similar check, but they return EINVAL instead, feel free to adjust if SUS or other standard mandates specific value suggested by Kamil Rytarowski To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fread.3 cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdio/fread.c cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/fwrite.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fread.3 diff -u src/lib/libc/stdio/fread.3:1.15 src/lib/libc/stdio/fread.3:1.16 --- src/lib/libc/stdio/fread.3:1.15 Sun Sep 11 04:55:48 2011 +++ src/lib/libc/stdio/fread.3 Mon Feb 1 17:50:53 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: fread.3,v 1.15 2011/09/11 04:55:48 jruoho Exp $ +.\" $NetBSD: fread.3,v 1.16 2021/02/01 17:50:53 jdolecek Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fread.3 8.2 (Berkeley) 3/8/94 .\" -.Dd September 11, 2011 +.Dd February 1, 2020 .Dt FREAD 3 .Os .Sh NAME @@ -96,6 +96,15 @@ or is 0, the functions return 0 and the state of .Fa stream remains unchanged. +.Pp +If the product of +.Fa size +and +.Fa nmemb +results in size_t overflow, 0 is returned and errno +is set to +.Er EOVERFLOW . + If an error occurs, or the end-of-file is reached, the return value is a short object count (or zero). .Pp Index: src/lib/libc/stdio/fread.c diff -u src/lib/libc/stdio/fread.c:1.24 src/lib/libc/stdio/fread.c:1.25 --- src/lib/libc/stdio/fread.c:1.24 Sun Jan 31 16:18:22 2021 +++ src/lib/libc/stdio/fread.c Mon Feb 1 17:50:53 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fread.c,v 1.24 2021/01/31 16:18:22 jdolecek Exp $ */ +/* $NetBSD: fread.c,v 1.25 2021/02/01 17:50:53 jdolecek Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #else -__RCSID("$NetBSD: fread.c,v 1.24 2021/01/31 16:18:22 jdolecek Exp $"); +__RCSID("$NetBSD: fread.c,v 1.25 2021/02/01 17:50:53 jdolecek Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,6 +48,8 @@ __RCSID("$NetBSD: fread.c,v 1.24 2021/01 #include "reentrant.h" #include "local.h" +#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) + size_t fread(void *buf, size_t size, size_t count, FILE *fp) { @@ -57,6 +59,17 @@ fread(void *buf, size_t size, size_t cou size_t total; _DIAGASSERT(fp != NULL); + + /* + * Extension: Catch integer overflow + */ + if ((size >= MUL_NO_OVERFLOW || count >= MUL_NO_OVERFLOW) && + size > 0 && count > SIZE_MAX / size) { + errno = EOVERFLOW; + fp->_flags |= __SERR; + return (0); + } + /* * The ANSI standard requires a return value of 0 for a count * or a size of 0. Whilst ANSI imposes no such requirements on Index: src/lib/libc/stdio/fwrite.c diff -u src/lib/libc/stdio/fwrite.c:1.18 src/lib/libc/stdio/fwrite.c:1.19 --- src/lib/libc/stdio/fwrite.c:1.18 Sun Feb 4 01:13:45 2018 +++ src/lib/libc/stdio/fwrite.c Mon Feb 1 17:50:53 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fwrite.c,v 1.18 2018/02/04 01:13:45 mrg Exp $ */ +/* $NetBSD: fwrite.c,v 1.19 2021/02/01 17:50:53 jdolecek Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fwrite.c,v 1.18 2018/02/04 01:13:45 mrg Exp $"); +__RCSID("$NetBSD: fwrite.c,v 1.19 2021/02/01 17:50:53 jdolecek Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,6 +48,8 @@ __RCSID("$NetBSD: fwrite.c,v 1.18 2018/0 #include "local.h" #include "fvwrite.h" +#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) + /* * Write `count' objects (each size `size') from memory to the given file. * Return the number of whole objects written. @@ -60,6 +62,16 @@ fwrite(const void *buf, size_t size, siz struct __siov iov; /* + * Extension: Catch integer overflow + */ + if ((size >= MUL_NO_OVERFLOW || count >= MUL_NO_OVERFLOW) && + size > 0 && count > SIZE_MAX / size) { + errno = EOVERFLOW; + fp->_flags |= __SERR; + return (0); + } + + /* * SUSv2 requires a return value of 0 for a count or a size of 0. */ if ((n = count * size) == 0)
Re: CVS commit: src/lib/libc/stdio
Date:Sun, 31 Jan 2021 18:34:22 +0100 From:Joerg Sonnenberger Message-ID: | That makes no sense. Just turn them into a short read, which is | something users have to deal with anyway. I'm not sure I agree with that one. If the user's size * nmemb overflows a size_t then the user is attempting something entirely insane (they cannot possibly have a buffer that big). Reading anything at all is most probably the wrong thing to do, as the args are very likely simply erroneous. EINVAL is not an unreasonable approach, I wouldn't even object to simply abort(). kre
Re: CVS commit: src/lib/libc/stdio
On 31.01.2021 18:34, Joerg Sonnenberger wrote: > On Sun, Jan 31, 2021 at 05:27:28PM +0100, Kamil Rytarowski wrote: >> On 31.01.2021 17:18, Jaromir Dolecek wrote: >>> Module Name:src >>> Committed By: jdolecek >>> Date: Sun Jan 31 16:18:22 UTC 2021 >>> >>> Modified Files: >>> src/lib/libc/stdio: fread.c >>> >>> Log Message: >>> for unbuffered I/O arrange for the destination buffer to be filled in one >>> go, instead of triggering long series of 1 byte read(2)s; this speeds up >>> fread() several order of magnitudes for this case, directly proportional >>> to the size of the supplied buffer >>> >>> change adapted from OpenBSD rev. 1.19 >>> >>> fixes PR lib/55808 by Roland Illig >>> >> >> While there it would be cool to apply FreeBSD and OpenBSD hardening for >> invalid size x nmemb, checking for overflow. I propose to return EINVAL >> in such case. > > That makes no sense. Just turn them into a short read, which is > something users have to deal with anyway. > > Joerg > The purpose of this errno is to catch insage usage of API that in normal circumstances never makes sense. With overflows (that are fine), the error can be unnoticed. Both FreeBSD and OpenBSD found this behavior as useful.
Re: CVS commit: src/lib/libc/stdio
On Sun, Jan 31, 2021 at 05:27:28PM +0100, Kamil Rytarowski wrote: > On 31.01.2021 17:18, Jaromir Dolecek wrote: > > Module Name:src > > Committed By: jdolecek > > Date: Sun Jan 31 16:18:22 UTC 2021 > > > > Modified Files: > > src/lib/libc/stdio: fread.c > > > > Log Message: > > for unbuffered I/O arrange for the destination buffer to be filled in one > > go, instead of triggering long series of 1 byte read(2)s; this speeds up > > fread() several order of magnitudes for this case, directly proportional > > to the size of the supplied buffer > > > > change adapted from OpenBSD rev. 1.19 > > > > fixes PR lib/55808 by Roland Illig > > > > While there it would be cool to apply FreeBSD and OpenBSD hardening for > invalid size x nmemb, checking for overflow. I propose to return EINVAL > in such case. That makes no sense. Just turn them into a short read, which is something users have to deal with anyway. Joerg
Re: CVS commit: src/lib/libc/stdio
On 31.01.2021 17:18, Jaromir Dolecek wrote: > Module Name: src > Committed By: jdolecek > Date: Sun Jan 31 16:18:22 UTC 2021 > > Modified Files: > src/lib/libc/stdio: fread.c > > Log Message: > for unbuffered I/O arrange for the destination buffer to be filled in one > go, instead of triggering long series of 1 byte read(2)s; this speeds up > fread() several order of magnitudes for this case, directly proportional > to the size of the supplied buffer > > change adapted from OpenBSD rev. 1.19 > > fixes PR lib/55808 by Roland Illig > While there it would be cool to apply FreeBSD and OpenBSD hardening for invalid size x nmemb, checking for overflow. I propose to return EINVAL in such case. I planned to submit it a while ago for discussion.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: jdolecek Date: Sun Jan 31 16:18:22 UTC 2021 Modified Files: src/lib/libc/stdio: fread.c Log Message: for unbuffered I/O arrange for the destination buffer to be filled in one go, instead of triggering long series of 1 byte read(2)s; this speeds up fread() several order of magnitudes for this case, directly proportional to the size of the supplied buffer change adapted from OpenBSD rev. 1.19 fixes PR lib/55808 by Roland Illig To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdio/fread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: jdolecek Date: Sun Jan 31 16:18:22 UTC 2021 Modified Files: src/lib/libc/stdio: fread.c Log Message: for unbuffered I/O arrange for the destination buffer to be filled in one go, instead of triggering long series of 1 byte read(2)s; this speeds up fread() several order of magnitudes for this case, directly proportional to the size of the supplied buffer change adapted from OpenBSD rev. 1.19 fixes PR lib/55808 by Roland Illig To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdio/fread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fread.c diff -u src/lib/libc/stdio/fread.c:1.23 src/lib/libc/stdio/fread.c:1.24 --- src/lib/libc/stdio/fread.c:1.23 Sat Feb 22 22:02:46 2020 +++ src/lib/libc/stdio/fread.c Sun Jan 31 16:18:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fread.c,v 1.23 2020/02/22 22:02:46 kamil Exp $ */ +/* $NetBSD: fread.c,v 1.24 2021/01/31 16:18:22 jdolecek Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #else -__RCSID("$NetBSD: fread.c,v 1.23 2020/02/22 22:02:46 kamil Exp $"); +__RCSID("$NetBSD: fread.c,v 1.24 2021/01/31 16:18:22 jdolecek Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -68,12 +68,38 @@ fread(void *buf, size_t size, size_t cou _DIAGASSERT(buf != NULL); FLOCKFILE(fp); + if (fp->_r < 0) + fp->_r = 0; total = resid; p = buf; - if (fp->_r <= 0) { - /* Nothing to read on enter, refill the buffers. */ - goto refill; + /* + * If we're unbuffered we know that the buffer in fp is empty so + * we can read directly into buf. This is much faster than a + * series of one byte reads into fp->_nbuf. + */ + if ((fp->_flags & __SNBF) != 0) { + while (resid > 0) { + /* set up the buffer */ + fp->_bf._base = fp->_p = (unsigned char *)p; + fp->_bf._size = resid; + + if (__srefill(fp)) { +/* no more input: return partial result */ +count = (total - resid) / size; +break; + } + p += fp->_r; + resid -= fp->_r; + } + + /* restore the old buffer (see __smakebuf) */ + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + fp->_r = 0; + + FUNLOCKFILE(fp); + return (count); } while (resid > (size_t)(r = fp->_r)) { @@ -82,7 +108,6 @@ fread(void *buf, size_t size, size_t cou /* fp->_r = 0 ... done in __srefill */ p += r; resid -= r; -refill: if (__srefill(fp)) { /* no more input: return partial result */ FUNLOCKFILE(fp);
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: rillig Date: Sat Aug 29 15:25:57 UTC 2020 Modified Files: src/lib/libc/stdio: stdio.3 Log Message: stdio(3): fix typos in the manual page fputc cannot read characters, it can only write them. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdio/stdio.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/stdio.3 diff -u src/lib/libc/stdio/stdio.3:1.27 src/lib/libc/stdio/stdio.3:1.28 --- src/lib/libc/stdio/stdio.3:1.27 Thu Feb 22 08:33:43 2018 +++ src/lib/libc/stdio/stdio.3 Sat Aug 29 15:25:57 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: stdio.3,v 1.27 2018/02/22 08:33:43 pgoyette Exp $ +.\" $NetBSD: stdio.3,v 1.28 2020/08/29 15:25:57 rillig Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)stdio.3 8.7 (Berkeley) 4/19/94 .\" -.Dd February 22, 2018 +.Dd August 29, 2020 .Dt STDIO 3 .Os .Sh NAME @@ -63,15 +63,13 @@ to a terminal) then a .Em file position indicator associated with the stream is positioned at the start of the file (byte zero), unless the file is opened with append mode. -If append mode -is used, the position indicator will be placed the end-of-file. +If append mode is used, the position indicator is placed at the end-of-file. The position indicator is maintained by subsequent reads, writes and positioning requests. -All input occurs as if the characters -were read by successive calls to the +All input occurs as if the characters were read by successive calls to the .Xr fgetc 3 function; all output takes place as if all characters were -read by successive calls to the +written by successive calls to the .Xr fputc 3 function. .Pp
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: rillig Date: Sat Aug 29 15:25:57 UTC 2020 Modified Files: src/lib/libc/stdio: stdio.3 Log Message: stdio(3): fix typos in the manual page fputc cannot read characters, it can only write them. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdio/stdio.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Aug 28 22:02:24 UTC 2020 Modified Files: src/lib/libc/stdio: vdprintf.c Log Message: Allow vdprintf to work on non-blocking non-regular files (Rob Newberry) To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdio/vdprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/vdprintf.c diff -u src/lib/libc/stdio/vdprintf.c:1.5 src/lib/libc/stdio/vdprintf.c:1.6 --- src/lib/libc/stdio/vdprintf.c:1.5 Tue Jan 10 12:45:12 2017 +++ src/lib/libc/stdio/vdprintf.c Fri Aug 28 18:02:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vdprintf.c,v 1.5 2017/01/10 17:45:12 christos Exp $ */ +/* $NetBSD: vdprintf.c,v 1.6 2020/08/28 22:02:24 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,12 +34,11 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vdprintf.c,v 1.5 2017/01/10 17:45:12 christos Exp $"); +__RCSID("$NetBSD: vdprintf.c,v 1.6 2020/08/28 22:02:24 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include -#include #include #include @@ -89,16 +88,6 @@ vdprintf_l(int fd, locale_t loc, const c return EOF; } - if (fdflags & O_NONBLOCK) { - struct stat st; - if (fstat(fd, ) == -1) - return -1; - if (!S_ISREG(st.st_mode)) { - errno = EFTYPE; - return EOF; - } - } - _FILEEXT_SETUP(, ); __sfpinit(); f._p = buf;
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Fri Aug 28 22:02:24 UTC 2020 Modified Files: src/lib/libc/stdio: vdprintf.c Log Message: Allow vdprintf to work on non-blocking non-regular files (Rob Newberry) To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdio/vdprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kamil Date: Sat Feb 22 22:02:46 UTC 2020 Modified Files: src/lib/libc/stdio: fread.c Log Message: Avoid undefined behavior in fread(3) On the first call to fread(3), just after fopen(3) the internal buffers are empty. This means that _r and _p (among others) are zeroed. Passing NULL to the 2nd argument of memcpy(3) for the zero length is undefined. Calling _p += 0 triggers LLVM UBSan (NULL pointer arithmetic). Calling _p += 0, p += 0 and resid -= 0 has no effect. Replace the "fp->_r = 0;" logic with a short circuit jump to __srefill() that sets _r internally and refills the FILE buffers. No functional change from an end user point of view, except skipping a few dummy operations on the first call, for a FILE pointer, to fread(3). To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/libc/stdio/fread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kamil Date: Sat Feb 22 22:02:46 UTC 2020 Modified Files: src/lib/libc/stdio: fread.c Log Message: Avoid undefined behavior in fread(3) On the first call to fread(3), just after fopen(3) the internal buffers are empty. This means that _r and _p (among others) are zeroed. Passing NULL to the 2nd argument of memcpy(3) for the zero length is undefined. Calling _p += 0 triggers LLVM UBSan (NULL pointer arithmetic). Calling _p += 0, p += 0 and resid -= 0 has no effect. Replace the "fp->_r = 0;" logic with a short circuit jump to __srefill() that sets _r internally and refills the FILE buffers. No functional change from an end user point of view, except skipping a few dummy operations on the first call, for a FILE pointer, to fread(3). To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/libc/stdio/fread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fread.c diff -u src/lib/libc/stdio/fread.c:1.22 src/lib/libc/stdio/fread.c:1.23 --- src/lib/libc/stdio/fread.c:1.22 Thu Mar 15 18:22:30 2012 +++ src/lib/libc/stdio/fread.c Sat Feb 22 22:02:46 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fread.c,v 1.22 2012/03/15 18:22:30 christos Exp $ */ +/* $NetBSD: fread.c,v 1.23 2020/02/22 22:02:46 kamil Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #else -__RCSID("$NetBSD: fread.c,v 1.22 2012/03/15 18:22:30 christos Exp $"); +__RCSID("$NetBSD: fread.c,v 1.23 2020/02/22 22:02:46 kamil Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -68,16 +68,21 @@ fread(void *buf, size_t size, size_t cou _DIAGASSERT(buf != NULL); FLOCKFILE(fp); - if (fp->_r < 0) - fp->_r = 0; total = resid; p = buf; + + if (fp->_r <= 0) { + /* Nothing to read on enter, refill the buffers. */ + goto refill; + } + while (resid > (size_t)(r = fp->_r)) { (void)memcpy(p, fp->_p, (size_t)r); fp->_p += r; /* fp->_r = 0 ... done in __srefill */ p += r; resid -= r; +refill: if (__srefill(fp)) { /* no more input: return partial result */ FUNLOCKFILE(fp);
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Sat Sep 7 11:53:27 UTC 2019 Modified Files: src/lib/libc/stdio: fflush.3 Log Message: Document history To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/fflush.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Sat Sep 7 11:53:27 UTC 2019 Modified Files: src/lib/libc/stdio: fflush.3 Log Message: Document history To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/fflush.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fflush.3 diff -u src/lib/libc/stdio/fflush.3:1.12 src/lib/libc/stdio/fflush.3:1.13 --- src/lib/libc/stdio/fflush.3:1.12 Thu Aug 7 16:43:22 2003 +++ src/lib/libc/stdio/fflush.3 Sat Sep 7 11:53:27 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: fflush.3,v 1.12 2003/08/07 16:43:22 agc Exp $ +.\" $NetBSD: fflush.3,v 1.13 2019/09/07 11:53:27 sevan Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fflush.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd September 7, 2019 .Dt FFLUSH 3 .Os .Sh NAME @@ -108,3 +108,12 @@ The function conforms to .St -ansiC . +.Sh HISTORY +The +.Fn fflush +function first appeared in +.At v4 . +The +.Fn fpurge +function first appeared in +.Bx 4.4 .
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Mon Sep 2 00:48:16 UTC 2019 Modified Files: src/lib/libc/stdio: putc.3 Log Message: putc & putw were in v1 https://www.bell-labs.com/usr/dmr/www/man31.pdf putchar was in v4 https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3 To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/putc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/putc.3 diff -u src/lib/libc/stdio/putc.3:1.13 src/lib/libc/stdio/putc.3:1.14 --- src/lib/libc/stdio/putc.3:1.13 Wed Feb 22 15:08:55 2017 +++ src/lib/libc/stdio/putc.3 Mon Sep 2 00:48:16 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: putc.3,v 1.13 2017/02/22 15:08:55 abhinav Exp $ +.\" $NetBSD: putc.3,v 1.14 2019/09/02 00:48:16 sevan Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)putc.3 8.1 (Berkeley) 6/4/93 .\" -.Dd May 6, 2010 +.Dd September 2, 2019 .Dt PUTC 3 .Os .Sh NAME @@ -152,13 +152,16 @@ and conform to .St -p1003.1-96 . .Sh HISTORY -The functions +The .Fn putc , -.Fn putchar , and .Fn putw -first appeared in -.At v6 . +functions first appeared in +.At v1 . +The +.Fn putchar +function first appeared in +.At v4 . The function .Fn fputc appeared in
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Mon Sep 2 00:48:16 UTC 2019 Modified Files: src/lib/libc/stdio: putc.3 Log Message: putc & putw were in v1 https://www.bell-labs.com/usr/dmr/www/man31.pdf putchar was in v4 https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3 To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/putc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Mon Sep 2 00:32:55 UTC 2019 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Start documenting history https://www.bell-labs.com/usr/dmr/www/man31.pdf To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fopen.3 diff -u src/lib/libc/stdio/fopen.3:1.35 src/lib/libc/stdio/fopen.3:1.36 --- src/lib/libc/stdio/fopen.3:1.35 Sat Nov 4 08:53:23 2017 +++ src/lib/libc/stdio/fopen.3 Mon Sep 2 00:32:55 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.35 2017/11/04 08:53:23 kre Exp $ +.\" $NetBSD: fopen.3,v 1.36 2019/09/02 00:32:55 sevan Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fopen.3 8.1 (Berkeley) 6/4/93 .\" -.Dd November 3, 2017 +.Dd September 2, 2019 .Dt FOPEN 3 .Os .Sh NAME @@ -298,6 +298,11 @@ functions conform to .St -ansiC . All three functions are specified in .St -p1003.1-2008 . +.Sh HISTORY +An +.Fn fopen +function appeared in +.At v1 . .Sh CAVEATS Proper code using .Fn fdopen
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Mon Sep 2 00:32:55 UTC 2019 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Start documenting history https://www.bell-labs.com/usr/dmr/www/man31.pdf To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Mon Sep 2 00:30:58 UTC 2019 Modified Files: src/lib/libc/stdio: getc.3 Log Message: Start documenting history https://www.bell-labs.com/usr/dmr/www/man31.pdf To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/getc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: sevan Date: Mon Sep 2 00:30:58 UTC 2019 Modified Files: src/lib/libc/stdio: getc.3 Log Message: Start documenting history https://www.bell-labs.com/usr/dmr/www/man31.pdf To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/getc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/getc.3 diff -u src/lib/libc/stdio/getc.3:1.12 src/lib/libc/stdio/getc.3:1.13 --- src/lib/libc/stdio/getc.3:1.12 Thu Aug 7 16:43:26 2003 +++ src/lib/libc/stdio/getc.3 Mon Sep 2 00:30:58 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: getc.3,v 1.12 2003/08/07 16:43:26 agc Exp $ +.\" $NetBSD: getc.3,v 1.13 2019/09/02 00:30:58 sevan Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)getc.3 8.1 (Berkeley) 6/4/93 .\" -.Dd April 25, 2001 +.Dd September 2, 2019 .Dt GETC 3 .Os .Sh NAME @@ -154,6 +154,13 @@ and .Fn getchar_unlocked functions conform to .St -p1003.1-96 . +.Sh HISTORY +The +.Fn getc +and +.Fn getw +functions appeared in +.At v1 . .Sh BUGS Since .Dv EOF
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Sun Sep 1 01:23:14 UTC 2019 Modified Files: src/lib/libc/stdio: tmpnam.3 Log Message: Refer to "w+" as "mode" as that's what fopen(3) calls it. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/tmpnam.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Sun Sep 1 01:23:14 UTC 2019 Modified Files: src/lib/libc/stdio: tmpnam.3 Log Message: Refer to "w+" as "mode" as that's what fopen(3) calls it. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/tmpnam.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/tmpnam.3 diff -u src/lib/libc/stdio/tmpnam.3:1.17 src/lib/libc/stdio/tmpnam.3:1.18 --- src/lib/libc/stdio/tmpnam.3:1.17 Fri Apr 30 04:55:10 2010 +++ src/lib/libc/stdio/tmpnam.3 Sun Sep 1 01:23:14 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: tmpnam.3,v 1.17 2010/04/30 04:55:10 jruoho Exp $ +.\" $NetBSD: tmpnam.3,v 1.18 2019/09/01 01:23:14 uwe Exp $ .\" .\" Copyright (c) 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -62,7 +62,7 @@ The created file is unlinked before .Fn tmpfile returns, causing the file to be automatically deleted when the last reference to it is closed. -The file is opened with the access value +The file is opened with the access mode .Ql w+ . .Pp The
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Thu Mar 21 21:13:45 UTC 2019 Modified Files: src/lib/libc/stdio: funopen.3 Log Message: Minor markup and wording fixes. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdio/funopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/funopen.3 diff -u src/lib/libc/stdio/funopen.3:1.24 src/lib/libc/stdio/funopen.3:1.25 --- src/lib/libc/stdio/funopen.3:1.24 Wed Apr 6 03:38:31 2016 +++ src/lib/libc/stdio/funopen.3 Thu Mar 21 21:13:45 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: funopen.3,v 1.24 2016/04/06 03:38:31 dholland Exp $ +.\" $NetBSD: funopen.3,v 1.25 2019/03/21 21:13:45 uwe Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -47,8 +47,22 @@ .Sh SYNOPSIS .In stdio.h .Ft FILE * -.Fn funopen "void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "off_t (*seekfn)(void *, off_t, int)" "int (*closefn)(void *)" -.Fn funopen2 "void *cookie" "ssize_t (*readfn)(void *, void *, size_t)" "ssize_t (*writefn)(void *, const void *, size_t)" "off_t (*seekfn)(void *, off_t, int)" "int (*flushfn)(void *)" "int (*closefn)(void *)" +.Fo funopen +.Fa "void *cookie" +.Fa "int (*readfn)(void *, char *, int)" +.Fa "int (*writefn)(void *, const char *, int)" +.Fa "off_t (*seekfn)(void *, off_t, int)" +.Fa "int (*closefn)(void *)" +.Fc +.Ft FILE * +.Fo funopen2 +.Fa "void *cookie" +.Fa "ssize_t (*readfn)(void *, void *, size_t)" +.Fa "ssize_t (*writefn)(void *, const void *, size_t)" +.Fa "off_t (*seekfn)(void *, off_t, int)" +.Fa "int (*flushfn)(void *)" +.Fa "int (*closefn)(void *)" +.Fc .Ft FILE * .Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)" .Ft FILE * @@ -126,7 +140,7 @@ Additionally, all of the functions shoul appropriately if an error occurs. .Pp An error on -.Fn closefn +.Fa closefn does not keep the stream open. .Pp As a convenience, the include file @@ -183,6 +197,6 @@ The functions first appeared in .Nx 7.0 . .Sh CAVEATS -All three functions are specific to +All these functions are specific to .Nx and thus unportable.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Thu Mar 21 21:13:45 UTC 2019 Modified Files: src/lib/libc/stdio: funopen.3 Log Message: Minor markup and wording fixes. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdio/funopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: mrg Date: Wed Jan 23 00:05:47 UTC 2019 Modified Files: src/lib/libc/stdio: fprintf.c Log Message: remove diag assert - the compiler demands fp is non NULL now. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdio/fprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fprintf.c diff -u src/lib/libc/stdio/fprintf.c:1.14 src/lib/libc/stdio/fprintf.c:1.15 --- src/lib/libc/stdio/fprintf.c:1.14 Sun Feb 4 01:13:45 2018 +++ src/lib/libc/stdio/fprintf.c Wed Jan 23 00:05:47 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: fprintf.c,v 1.14 2018/02/04 01:13:45 mrg Exp $ */ +/* $NetBSD: fprintf.c,v 1.15 2019/01/23 00:05:47 mrg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fprintf.c,v 1.14 2018/02/04 01:13:45 mrg Exp $"); +__RCSID("$NetBSD: fprintf.c,v 1.15 2019/01/23 00:05:47 mrg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,8 +53,6 @@ fprintf(FILE *fp, const char *fmt, ...) int ret; va_list ap; - _DIAGASSERT(fp != NULL); - va_start(ap, fmt); ret = vfprintf(fp, fmt, ap); va_end(ap);
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: mrg Date: Wed Jan 23 00:05:47 UTC 2019 Modified Files: src/lib/libc/stdio: fprintf.c Log Message: remove diag assert - the compiler demands fp is non NULL now. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdio/fprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Fri Dec 14 03:43:22 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Don't leave a subordinate clause out in the cold. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Fri Dec 14 03:43:22 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Don't leave a subordinate clause out in the cold. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/setbuf.3 diff -u src/lib/libc/stdio/setbuf.3:1.19 src/lib/libc/stdio/setbuf.3:1.20 --- src/lib/libc/stdio/setbuf.3:1.19 Tue Feb 20 17:23:39 2018 +++ src/lib/libc/stdio/setbuf.3 Fri Dec 14 03:43:22 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: setbuf.3,v 1.19 2018/02/20 17:23:39 uwe Exp $ +.\" $NetBSD: setbuf.3,v 1.20 2018/12/14 03:43:22 uwe Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -66,10 +66,10 @@ output or input is read from any stream .Va stdin ) . .Pp The default buffer settings can be overwritten per descriptor -.Ev ( STDBUF Ns Ar n ) +.Ev ( STDBUF Ns Ar n , where .Ar n -is the numeric value of the file descriptor represented by the stream, or +is the numeric value of the file descriptor represented by the stream), or for all descriptors .Ev ( STDBUF ) . The environment variable value is a letter followed by an optional numeric
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Fri Dec 14 03:29:54 UTC 2018 Modified Files: src/lib/libc/stdio: makebuf.c Log Message: Fix typo in the function comment. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/makebuf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/makebuf.c diff -u src/lib/libc/stdio/makebuf.c:1.18 src/lib/libc/stdio/makebuf.c:1.19 --- src/lib/libc/stdio/makebuf.c:1.18 Wed Jul 15 19:08:43 2015 +++ src/lib/libc/stdio/makebuf.c Fri Dec 14 03:29:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: makebuf.c,v 1.18 2015/07/15 19:08:43 christos Exp $ */ +/* $NetBSD: makebuf.c,v 1.19 2018/12/14 03:29:54 uwe Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: makebuf.c,v 1.18 2015/07/15 19:08:43 christos Exp $"); +__RCSID("$NetBSD: makebuf.c,v 1.19 2018/12/14 03:29:54 uwe Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,7 +57,7 @@ __RCSID("$NetBSD: makebuf.c,v 1.18 2015/ /* * Override the file buffering based on the environment setting STDBUF%d * (for the specific file descriptor) and STDBUF (for all descriptors). - * the setting is ULB standing for "Unbuffered", "Linebuffered", + * the setting is ULF standing for "Unbuffered", "Linebuffered", * and Fullybuffered", and is a value from 0 to 1M. */ static int
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Fri Dec 14 03:29:54 UTC 2018 Modified Files: src/lib/libc/stdio: makebuf.c Log Message: Fix typo in the function comment. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/makebuf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: msaitoh Date: Wed Jul 4 07:38:38 UTC 2018 Modified Files: src/lib/libc/stdio: fgetln.3 Log Message: Indent. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fgetln.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fgetln.3 diff -u src/lib/libc/stdio/fgetln.3:1.15 src/lib/libc/stdio/fgetln.3:1.16 --- src/lib/libc/stdio/fgetln.3:1.15 Thu Jun 19 14:27:50 2014 +++ src/lib/libc/stdio/fgetln.3 Wed Jul 4 07:38:38 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: fgetln.3,v 1.15 2014/06/19 14:27:50 christos Exp $ +.\" $NetBSD: fgetln.3,v 1.16 2018/07/04 07:38:38 msaitoh Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94 .\" -.Dd June 19, 2014 +.Dd July 4, 2018 .Dt FGETLN 3 .Os .Sh NAME @@ -138,7 +138,7 @@ temporary buffer: if (len > 0 && buf[len - 1] == '\en') buf[len - 1] = '\e0'; else if ((lbuf = strndup(buf, len + 1)) == NULL) -err(1, NULL); + err(1, NULL); printf("%s\en", lbuf); if (lbuf != buf)
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: msaitoh Date: Wed Jul 4 07:38:38 UTC 2018 Modified Files: src/lib/libc/stdio: fgetln.3 Log Message: Indent. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fgetln.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: pgoyette Date: Thu Feb 22 08:33:43 UTC 2018 Modified Files: src/lib/libc/stdio: stdio.3 Log Message: Remove extra "an" Thanks to J. Lewis Muir To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdio/stdio.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/stdio.3 diff -u src/lib/libc/stdio/stdio.3:1.26 src/lib/libc/stdio/stdio.3:1.27 --- src/lib/libc/stdio/stdio.3:1.26 Sun Sep 6 04:20:50 2015 +++ src/lib/libc/stdio/stdio.3 Thu Feb 22 08:33:43 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: stdio.3,v 1.26 2015/09/06 04:20:50 mrg Exp $ +.\" $NetBSD: stdio.3,v 1.27 2018/02/22 08:33:43 pgoyette Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)stdio.3 8.7 (Berkeley) 4/19/94 .\" -.Dd September 6, 2015 +.Dd February 22, 2018 .Dt STDIO 3 .Os .Sh NAME @@ -137,7 +137,7 @@ In fact, freshly-opened streams that refer to terminal devices default to line buffering, and pending output to such streams is written automatically -whenever an such an input stream is read. +whenever such an input stream is read. Note that this applies only to .Dq "true reads" ; if the read request can be satisfied by existing buffered data,
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: pgoyette Date: Thu Feb 22 08:33:43 UTC 2018 Modified Files: src/lib/libc/stdio: stdio.3 Log Message: Remove extra "an" Thanks to J. Lewis Muir To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdio/stdio.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Tue Feb 20 17:23:40 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Markup "stdin". To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Tue Feb 20 17:23:40 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Markup "stdin". To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/setbuf.3 diff -u src/lib/libc/stdio/setbuf.3:1.18 src/lib/libc/stdio/setbuf.3:1.19 --- src/lib/libc/stdio/setbuf.3:1.18 Tue Feb 20 17:21:11 2018 +++ src/lib/libc/stdio/setbuf.3 Tue Feb 20 17:23:39 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: setbuf.3,v 1.18 2018/02/20 17:21:11 uwe Exp $ +.\" $NetBSD: setbuf.3,v 1.19 2018/02/20 17:23:39 uwe Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -62,7 +62,8 @@ destination file or terminal as soon as when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a newline is output or input is read from any stream attached to a terminal device -(typically stdin). +(typically +.Va stdin ) . .Pp The default buffer settings can be overwritten per descriptor .Ev ( STDBUF Ns Ar n )
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Tue Feb 20 17:21:11 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Make the list of STDBUF values and the list of mode values congruent in formatting and spelling. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Tue Feb 20 17:21:11 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Make the list of STDBUF values and the list of mode values congruent in formatting and spelling. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/setbuf.3 diff -u src/lib/libc/stdio/setbuf.3:1.17 src/lib/libc/stdio/setbuf.3:1.18 --- src/lib/libc/stdio/setbuf.3:1.17 Tue Feb 20 17:16:51 2018 +++ src/lib/libc/stdio/setbuf.3 Tue Feb 20 17:21:11 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: setbuf.3,v 1.17 2018/02/20 17:16:51 uwe Exp $ +.\" $NetBSD: setbuf.3,v 1.18 2018/02/20 17:21:11 uwe Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -75,13 +75,13 @@ The environment variable value is a lett value indicating the size of the buffer. Valid sizes range from 0B to 1MB. Valid letters are: -.Bl -tag -width X +.Bl -tag -offset indent -width X .It Li U -Unbuffered. +unbuffered .It Li L -Line-buffered. +line buffered .It Li F -Fully-buffered. +fully buffered .El .Pp The function
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Tue Feb 20 17:16:51 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Use semantic markup. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: uwe Date: Tue Feb 20 17:16:51 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Use semantic markup. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/setbuf.3 diff -u src/lib/libc/stdio/setbuf.3:1.16 src/lib/libc/stdio/setbuf.3:1.17 --- src/lib/libc/stdio/setbuf.3:1.16 Tue Feb 20 09:36:26 2018 +++ src/lib/libc/stdio/setbuf.3 Tue Feb 20 17:16:51 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: setbuf.3,v 1.16 2018/02/20 09:36:26 wiz Exp $ +.\" $NetBSD: setbuf.3,v 1.17 2018/02/20 17:16:51 uwe Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -65,12 +65,12 @@ output or input is read from any stream (typically stdin). .Pp The default buffer settings can be overwritten per descriptor -.Dv ( STDBUFn ) +.Ev ( STDBUF Ns Ar n ) where -.Dv n +.Ar n is the numeric value of the file descriptor represented by the stream, or for all descriptors -.Dv ( STDBUF ) . +.Ev ( STDBUF ) . The environment variable value is a letter followed by an optional numeric value indicating the size of the buffer. Valid sizes range from 0B to 1MB. @@ -97,10 +97,10 @@ is called, and an optimally-sized buffer is obtained. If a stream refers to a terminal (as -.Em stdout +.Va stdout normally does) it is line buffered. The standard error stream -.Em stderr +.Va stderr is initially unbuffered. .Pp The
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Tue Feb 20 09:36:26 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Remove ineffective macros and arguments. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Tue Feb 20 09:36:26 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Remove ineffective macros and arguments. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/setbuf.3 diff -u src/lib/libc/stdio/setbuf.3:1.15 src/lib/libc/stdio/setbuf.3:1.16 --- src/lib/libc/stdio/setbuf.3:1.15 Tue Feb 20 02:52:41 2018 +++ src/lib/libc/stdio/setbuf.3 Tue Feb 20 09:36:26 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: setbuf.3,v 1.15 2018/02/20 02:52:41 kamil Exp $ +.\" $NetBSD: setbuf.3,v 1.16 2018/02/20 09:36:26 wiz Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -75,12 +75,12 @@ The environment variable value is a lett value indicating the size of the buffer. Valid sizes range from 0B to 1MB. Valid letters are: -.Bl -tag -width X -indent -.It Dv Li U +.Bl -tag -width X +.It Li U Unbuffered. -.It Dv Li L +.It Li L Line-buffered. -.It Dv Li F +.It Li F Fully-buffered. .El .Pp @@ -91,9 +91,7 @@ may be used to force the block out early .Xr fclose 3 . ) .Pp Normally all files are block buffered. -When the first -.Tn I/O -operation occurs on a file, +When the first I/O operation occurs on a file, .Xr malloc 3 is called, and an optimally-sized buffer is obtained. @@ -153,9 +151,7 @@ but may have peculiar side effects (such as discarding input or flushing output) if the stream is ``active''. Portable applications should call it only once on any given stream, -and before any -.Tn I/O -is performed. +and before any I/O is performed. .Pp The other three calls are, in effect, simply aliases for calls to .Fn setvbuf .
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kamil Date: Tue Feb 20 02:52:41 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Improve the setbuf(3) man-page Move historical lines to newly added HISTORY section. Additional historical notes obtained from OpenBSD. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kamil Date: Tue Feb 20 02:52:41 UTC 2018 Modified Files: src/lib/libc/stdio: setbuf.3 Log Message: Improve the setbuf(3) man-page Move historical lines to newly added HISTORY section. Additional historical notes obtained from OpenBSD. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdio/setbuf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/setbuf.3 diff -u src/lib/libc/stdio/setbuf.3:1.14 src/lib/libc/stdio/setbuf.3:1.15 --- src/lib/libc/stdio/setbuf.3:1.14 Wed Jul 15 19:08:43 2015 +++ src/lib/libc/stdio/setbuf.3 Tue Feb 20 02:52:41 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: setbuf.3,v 1.14 2015/07/15 19:08:43 christos Exp $ +.\" $NetBSD: setbuf.3,v 1.15 2018/02/20 02:52:41 kamil Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -205,19 +205,24 @@ and functions conform to .St -ansiC . -.Sh BUGS +.Sh HISTORY +The +.Fn setbuf +function first appeared in +.At v7 . The .Fn setbuffer -and +function first appeared in +.Bx 4.1c . +The .Fn setlinebuf -functions are not portable to versions of -.Bx -before +function first appeared in .Bx 4.2 . -On -.Bx 4.2 -and -.Bx 4.3 -systems, +The +.Fn setvbuf +function first appeared in +.Bx 4.4 . +.Sh BUGS +The .Fn setbuf -always uses a suboptimal buffer size and should be avoided. +function usually uses a suboptimal buffer size and should be avoided.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: dholland Date: Sun Dec 31 07:22:55 UTC 2017 Modified Files: src/lib/libc/stdio: printf.3 Log Message: Fix plurals. To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 src/lib/libc/stdio/printf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/printf.3 diff -u src/lib/libc/stdio/printf.3:1.67 src/lib/libc/stdio/printf.3:1.68 --- src/lib/libc/stdio/printf.3:1.67 Mon Jul 3 21:32:49 2017 +++ src/lib/libc/stdio/printf.3 Sun Dec 31 07:22:55 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: printf.3,v 1.67 2017/07/03 21:32:49 wiz Exp $ +.\" $NetBSD: printf.3,v 1.68 2017/12/31 07:22:55 dholland Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -370,7 +370,7 @@ The following length modifiers are valid .Cm d , i , n , o , u , x , or .Cm X -conversion: +conversions: .Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *" .It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n .It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *" @@ -416,7 +416,7 @@ macros are used when possible. These are further described in .Xr inttypes 3 . .Pp -The following length modifier is valid for the +The following length modifiers are valid for the .Cm a , .Cm A , .Cm e , @@ -426,7 +426,7 @@ The following length modifier is valid f .Cm g , or .Cm G -conversion: +conversions: .Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G" .It Sy Modifier Ta Cm a , A , e , E , f , F , g , G .It Cm l No (ell) Ta Vt double @@ -438,7 +438,7 @@ The following length modifier is valid f .Cm c or .Cm s -conversion: +conversions: .Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *" .It Sy Modifier Ta Cm c Ta Cm s .It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: dholland Date: Sun Dec 31 07:22:55 UTC 2017 Modified Files: src/lib/libc/stdio: printf.3 Log Message: Fix plurals. To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 src/lib/libc/stdio/printf.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kre Date: Sat Nov 4 08:53:24 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Be more consistent with how we refer to fopen() - pointed out by wiz@ To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fopen.3 diff -u src/lib/libc/stdio/fopen.3:1.34 src/lib/libc/stdio/fopen.3:1.35 --- src/lib/libc/stdio/fopen.3:1.34 Sat Nov 4 08:04:40 2017 +++ src/lib/libc/stdio/fopen.3 Sat Nov 4 08:53:23 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.34 2017/11/04 08:04:40 kre Exp $ +.\" $NetBSD: fopen.3,v 1.35 2017/11/04 08:53:23 kre Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -139,7 +139,7 @@ The letter in the mode turns on exclusive open mode to the file .Pq Dv O_EXCL which means that the file will not be created if it already exists. -In that case, the +In that case .Fn fopen will fail. .El
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kre Date: Sat Nov 4 08:53:24 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Be more consistent with how we refer to fopen() - pointed out by wiz@ To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kre Date: Sat Nov 4 08:04:40 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Some (mostly minor) wording improvements (IMO) To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fopen.3 diff -u src/lib/libc/stdio/fopen.3:1.33 src/lib/libc/stdio/fopen.3:1.34 --- src/lib/libc/stdio/fopen.3:1.33 Sat Nov 4 07:59:17 2017 +++ src/lib/libc/stdio/fopen.3 Sat Nov 4 08:04:40 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.33 2017/11/04 07:59:17 wiz Exp $ +.\" $NetBSD: fopen.3,v 1.34 2017/11/04 08:04:40 kre Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -62,29 +62,30 @@ and associates a stream with it. The argument .Fa mode points to a string beginning with one of the following -sequences (Additional characters may follow these sequences.): +sequences, which may be followed by additional modifiers +as indicated below: .Bl -tag -width 4n .It Dq Li a -Append; open for writing. +Append; open an existing or new file for writing in append mode. The file is created if it does not exist. .It Dq Li a+ -Append; open for reading and writing. +Open for reading and writing in append mode. The file is created if it does not exist. .It Dq Li r -Open for reading. +Read; open an existing file for reading. .It Dq Li r+ -Open for reading and writing. +Open an existing file for reading and writing. .It Dq Li w -Open for writing. -Truncate file to zero length or create file. +Write; open an empty file for writing. +Truncate an existing file to zero length or create a new file. .It Dq Li w+ -Open for reading and writing. +Open an empty file for reading and writing. Truncate file to zero length or create file. .El .Pp -Additionally, the +After one of those, the .Fa mode -string can also include one of the following letters: +string can also include one or more of the following modifier letters: .Bl -tag -width 4n .It Sq b The letter @@ -92,8 +93,11 @@ The letter may appear either as a last character or as a character between the characters in any of the two-character strings described above. This is strictly for compatibility with -.St -ansiC -and has no effect; the +.St -ansiC , +where it means open in +.Dq binary +mode which is identical to text mode here, +so has no effect; the .Sq b is ignored. .It Sq e @@ -115,7 +119,7 @@ in the mode string restricts .Fn fopen to regular files; if the file opened is not a regular file, .Fn fopen -will fail. +will close it, and fail. This is a non .St -ansiC extension. @@ -135,6 +139,9 @@ The letter in the mode turns on exclusive open mode to the file .Pq Dv O_EXCL which means that the file will not be created if it already exists. +In that case, the +.Fn fopen +will fail. .El .Pp Any created files will have mode
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kre Date: Sat Nov 4 08:04:40 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Some (mostly minor) wording improvements (IMO) To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Sat Nov 4 07:59:17 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Fix xref. Remove Tn. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fopen.3 diff -u src/lib/libc/stdio/fopen.3:1.32 src/lib/libc/stdio/fopen.3:1.33 --- src/lib/libc/stdio/fopen.3:1.32 Sat Nov 4 02:49:55 2017 +++ src/lib/libc/stdio/fopen.3 Sat Nov 4 07:59:17 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.32 2017/11/04 02:49:55 christos Exp $ +.\" $NetBSD: fopen.3,v 1.33 2017/11/04 07:59:17 wiz Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -99,11 +99,11 @@ is ignored. .It Sq e The letter .Sq e -in the mode string sets the close-on-exec +in the mode string sets the close-on-exec .Pq Dv O_CLOEXEC flag of the file descriptor, which means that it will not be available after an -.Xr exec 2 +.Xr exec 3 system call. This is a non .St -ansiC @@ -221,9 +221,7 @@ Upon successful completion .Fn fdopen and .Fn freopen -return a -.Tn FILE -pointer. +return a FILE pointer. Otherwise, .Dv NULL is returned and the global variable
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Sat Nov 4 07:59:17 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.3 Log Message: Fix xref. Remove Tn. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kre Date: Sat Nov 4 07:26:35 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.c Log Message: Avoid losing a fd (ie: close it) in the (ever so likely) case that the fd exceeds the limits of what can be stored in a FILE (65535). To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fopen.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fopen.c diff -u src/lib/libc/stdio/fopen.c:1.15 src/lib/libc/stdio/fopen.c:1.16 --- src/lib/libc/stdio/fopen.c:1.15 Thu Mar 15 18:22:30 2012 +++ src/lib/libc/stdio/fopen.c Sat Nov 4 07:26:35 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $ */ +/* $NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $"); +__RCSID("$NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -88,6 +88,7 @@ fopen(const char *file, const char *mode * open. (We treat the short as unsigned, and special-case -1). */ if (f >= USHRT_MAX) { + (void)close(f); errno = EMFILE; goto release; }
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: kre Date: Sat Nov 4 07:26:35 UTC 2017 Modified Files: src/lib/libc/stdio: fopen.c Log Message: Avoid losing a fd (ie: close it) in the (ever so likely) case that the fd exceeds the limits of what can be stored in a FILE (65535). To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fopen.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Sat Nov 4 02:49:55 UTC 2017 Modified Files: src/lib/libc/stdio: flags.c fopen.3 Log Message: Implement nofollow (l) for fopen(3). To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/flags.c cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: christos Date: Sat Nov 4 02:49:55 UTC 2017 Modified Files: src/lib/libc/stdio: flags.c fopen.3 Log Message: Implement nofollow (l) for fopen(3). To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/flags.c cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/flags.c diff -u src/lib/libc/stdio/flags.c:1.17 src/lib/libc/stdio/flags.c:1.18 --- src/lib/libc/stdio/flags.c:1.17 Wed Nov 14 22:50:36 2012 +++ src/lib/libc/stdio/flags.c Fri Nov 3 22:49:55 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $ */ +/* $NetBSD: flags.c,v 1.18 2017/11/04 02:49:55 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $"); +__RCSID("$NetBSD: flags.c,v 1.18 2017/11/04 02:49:55 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -88,8 +88,9 @@ __sflags(const char *mode, int *optr) /* * [rwa]\+ or [rwa]b\+ means read and write - * f means open only plain files, * e means set close on exec. + * f means open only plain files. + * l means don't follow symlinks. * x means exclusive open. */ for (; *mode; mode++) @@ -98,17 +99,20 @@ __sflags(const char *mode, int *optr) ret = __SRW; m = O_RDWR; break; - case 'f': - o |= O_NONBLOCK; + case 'b': break; case 'e': o |= O_CLOEXEC; break; + case 'f': + o |= O_NONBLOCK; + break; + case 'l': + o |= O_NOFOLLOW; + break; case 'x': o |= O_EXCL; break; - case 'b': - break; default: /* We could produce a warning here */ break; } Index: src/lib/libc/stdio/fopen.3 diff -u src/lib/libc/stdio/fopen.3:1.31 src/lib/libc/stdio/fopen.3:1.32 --- src/lib/libc/stdio/fopen.3:1.31 Wed Jul 15 15:08:43 2015 +++ src/lib/libc/stdio/fopen.3 Fri Nov 3 22:49:55 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.31 2015/07/15 19:08:43 christos Exp $ +.\" $NetBSD: fopen.3,v 1.32 2017/11/04 02:49:55 christos Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fopen.3 8.1 (Berkeley) 6/4/93 .\" -.Dd November 14, 2012 +.Dd November 3, 2017 .Dt FOPEN 3 .Os .Sh NAME @@ -99,10 +99,12 @@ is ignored. .It Sq e The letter .Sq e -in the mode string sets the close-on-exec flag in the file descriptors of -the newly opened file files; if the operation fails, -.Fn fopen -will fail. +in the mode string sets the close-on-exec +.Pq Dv O_CLOEXEC +flag of the file descriptor, which means that it will not be available +after an +.Xr exec 2 +system call. This is a non .St -ansiC extension. @@ -117,6 +119,16 @@ will fail. This is a non .St -ansiC extension. +.It Sq l +The letter +.Sq l +in the mode string turns the don't-follow-symlinks +.Pq Dv O_NOFOLLOW +flag of the file descriptor, which means that if the last path component +is a symbolic link, it will not be followed. +This is a non +.St -ansiC +extension. .It Sq x The letter .Sq x
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: abhinav Date: Wed Oct 25 17:03:31 UTC 2017 Modified Files: src/lib/libc/stdio: getwc.3 Log Message: Remove comma after last Nm entry To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdio/getwc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: abhinav Date: Wed Oct 25 17:03:31 UTC 2017 Modified Files: src/lib/libc/stdio: getwc.3 Log Message: Remove comma after last Nm entry To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdio/getwc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/getwc.3 diff -u src/lib/libc/stdio/getwc.3:1.9 src/lib/libc/stdio/getwc.3:1.10 --- src/lib/libc/stdio/getwc.3:1.9 Thu Dec 16 17:42:27 2010 +++ src/lib/libc/stdio/getwc.3 Wed Oct 25 17:03:30 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: getwc.3,v 1.9 2010/12/16 17:42:27 wiz Exp $ +.\" $NetBSD: getwc.3,v 1.10 2017/10/25 17:03:30 abhinav Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -39,7 +39,7 @@ .Sh NAME .Nm fgetwc , .Nm getwc , -.Nm getwchar , +.Nm getwchar .Nd get next wide character from input stream .Sh LIBRARY .Lb libc
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Sun Jul 30 23:13:24 UTC 2017 Modified Files: src/lib/libc/stdio: fputs.3 Log Message: Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/fputs.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: wiz Date: Sun Jul 30 23:13:24 UTC 2017 Modified Files: src/lib/libc/stdio: fputs.3 Log Message: Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/fputs.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fputs.3 diff -u src/lib/libc/stdio/fputs.3:1.13 src/lib/libc/stdio/fputs.3:1.14 --- src/lib/libc/stdio/fputs.3:1.13 Sun Jul 30 22:53:56 2017 +++ src/lib/libc/stdio/fputs.3 Sun Jul 30 23:13:24 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fputs.3,v 1.13 2017/07/30 22:53:56 cheusov Exp $ +.\" $NetBSD: fputs.3,v 1.14 2017/07/30 23:13:24 wiz Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fputs.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd July 30, 2017 .Dt FPUTS 3 .Os .Sh NAME
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: cheusov Date: Sun Jul 30 22:53:56 UTC 2017 Modified Files: src/lib/libc/stdio: fputs.3 Log Message: According to POSIX return value of fputs(3) should be a non-netagive value if it succeeds To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/fputs.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/stdio/fputs.3 diff -u src/lib/libc/stdio/fputs.3:1.12 src/lib/libc/stdio/fputs.3:1.13 --- src/lib/libc/stdio/fputs.3:1.12 Wed Feb 22 14:58:33 2017 +++ src/lib/libc/stdio/fputs.3 Sun Jul 30 22:53:56 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fputs.3,v 1.12 2017/02/22 14:58:33 abhinav Exp $ +.\" $NetBSD: fputs.3,v 1.13 2017/07/30 22:53:56 cheusov Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -67,14 +67,11 @@ and a terminating newline character, to the stream .Em stdout . .Sh RETURN VALUES -The +The functions .Fn fputs -function -returns 0 on success and -.Dv EOF -on error; +and .Fn puts -returns a nonnegative integer on success and +return a nonnegative integer on success and .Dv EOF on error. .Sh ERRORS
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: cheusov Date: Sun Jul 30 22:53:56 UTC 2017 Modified Files: src/lib/libc/stdio: fputs.3 Log Message: According to POSIX return value of fputs(3) should be a non-netagive value if it succeeds To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/fputs.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdio
Module Name:src Committed By: perseant Date: Tue Jul 11 19:36:38 UTC 2017 Modified Files: src/lib/libc/stdio: vfwprintf.c Log Message: A more correct fix for PR standards/52282. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/libc/stdio/vfwprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.