CVS commit: src/lib/libc/stdio

2021-07-22 Thread Christos Zoulas
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

2021-07-22 Thread Christos Zoulas
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

2021-07-19 Thread Christos Zoulas
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

2021-07-16 Thread Christos Zoulas
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

2021-07-09 Thread Christos Zoulas
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

2021-07-08 Thread Christos Zoulas
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

2021-07-08 Thread Christos Zoulas
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

2021-07-06 Thread Christos Zoulas
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

2021-07-05 Thread Christos Zoulas
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

2021-02-07 Thread Jaromir Dolecek
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);



CVS commit: src/lib/libc/stdio

2021-02-01 Thread Jaromir Dolecek
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)



CVS commit: src/lib/libc/stdio

2021-01-31 Thread Jaromir Dolecek
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

2020-08-29 Thread Roland Illig
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

2020-08-28 Thread Christos Zoulas
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

2020-02-22 Thread Kamil Rytarowski
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

2019-03-21 Thread Valeriy E. Ushakov
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

2019-01-22 Thread matthew green
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

2018-12-13 Thread Valeriy E. Ushakov
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

2018-12-13 Thread Valeriy E. Ushakov
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

2018-07-04 Thread SAITOH Masanobu
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

2018-02-22 Thread Paul Goyette
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

2018-02-20 Thread Valeriy E. Ushakov
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

2018-02-20 Thread Valeriy E. Ushakov
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

2018-02-20 Thread Valeriy E. Ushakov
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

2018-02-20 Thread Thomas Klausner
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

2018-02-19 Thread Kamil Rytarowski
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

2017-12-30 Thread David A. Holland
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

2017-11-04 Thread Robert Elz
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

2017-11-04 Thread Robert Elz
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

2017-11-04 Thread Thomas Klausner
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

2017-11-04 Thread Robert Elz
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

2017-11-03 Thread Christos Zoulas
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

2017-10-25 Thread Abhinav Upadhyay
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

2017-07-30 Thread Thomas Klausner
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

2017-07-30 Thread Aleksey Cheusov
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

2017-07-11 Thread Konrad Schroder
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.

Modified files:

Index: src/lib/libc/stdio/vfwprintf.c
diff -u src/lib/libc/stdio/vfwprintf.c:1.35 src/lib/libc/stdio/vfwprintf.c:1.36
--- src/lib/libc/stdio/vfwprintf.c:1.35	Mon Jul 10 22:49:40 2017
+++ src/lib/libc/stdio/vfwprintf.c	Tue Jul 11 19:36:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.35 2017/07/10 22:49:40 perseant Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.36 2017/07/11 19:36:38 perseant 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.35 2017/07/10 22:49:40 perseant Exp $");
+__RCSID("$NetBSD: vfwprintf.c,v 1.36 2017/07/11 19:36:38 perseant Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -930,7 +930,7 @@ reswitch:	switch (ch) {
 flags |= GROUPING;
 			else {
 thousands_sep = '\0';
-grouping = "";
+grouping = NULL;
 			}
 			goto rflag;
 		case '.':



CVS commit: src/lib/libc/stdio

2017-07-10 Thread Konrad Schroder
Module Name:src
Committed By:   perseant
Date:   Mon Jul 10 22:49:40 UTC 2017

Modified Files:
src/lib/libc/stdio: vfwprintf.c

Log Message:
Do not use thousands grouping when none is specified by the locale.
Fixes PR standards/52282.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.34 src/lib/libc/stdio/vfwprintf.c:1.35
--- src/lib/libc/stdio/vfwprintf.c:1.34	Mon Jan 20 14:11:03 2014
+++ src/lib/libc/stdio/vfwprintf.c	Mon Jul 10 22:49:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.35 2017/07/10 22:49:40 perseant 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.34 2014/01/20 14:11:03 yamt Exp $");
+__RCSID("$NetBSD: vfwprintf.c,v 1.35 2017/07/10 22:49:40 perseant Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -923,15 +923,15 @@ reswitch:	switch (ch) {
 			sign = '+';
 			goto rflag;
 		case '\'':
-			flags |= GROUPING;
 			thousands_sep = *(localeconv_l(loc)->thousands_sep);
 			grouping = localeconv_l(loc)->grouping;
-			/* If the locale doesn't define the above, use sane
-			 * defaults - otherwise silly things happen! */
-			if (thousands_sep == 0)
-thousands_sep = ',';
-			if (!grouping || !*grouping)
-grouping = "\3";
+			/* Use grouping if defined by locale */
+			if (thousands_sep && grouping && *grouping)
+flags |= GROUPING;
+			else {
+thousands_sep = '\0';
+grouping = "";
+			}
 			goto rflag;
 		case '.':
 			if ((ch = *fmt++) == '*') {



CVS commit: src/lib/libc/stdio

2017-06-08 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Thu Jun  8 15:59:45 UTC 2017

Modified Files:
src/lib/libc/stdio: fgetln.c fgetstr.c getdelim.c

Log Message:
Don't use "NULL" to talk about null-terminated strings.

The C standard seems to be inconsistent about dash vs. space.  Old
text uses dash, Annex K uses space.  I'll let wizd(8) to sort that
out.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/fgetln.c
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdio/fgetstr.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/getdelim.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/fgetln.c
diff -u src/lib/libc/stdio/fgetln.c:1.16 src/lib/libc/stdio/fgetln.c:1.17
--- src/lib/libc/stdio/fgetln.c:1.16	Wed Dec  2 09:03:13 2009
+++ src/lib/libc/stdio/fgetln.c	Thu Jun  8 15:59:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fgetln.c,v 1.16 2009/12/02 09:03:13 roy Exp $	*/
+/*	$NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: fgetln.c,v 1.16 2009/12/02 09:03:13 roy Exp $");
+__RCSID("$NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $");
 
 #include "namespace.h"
 
@@ -49,7 +49,7 @@ __weak_alias(fgetln,_fgetln)
 /*
  * Get an input line.
  * This now uses getdelim(3) for a code reduction.
- * The upside is that strings are now always NULL terminated, but relying
+ * The upside is that strings are now always null-terminated, but relying
  * on this is non portable - better to use the POSIX getdelim(3) function.
  */
 char *

Index: src/lib/libc/stdio/fgetstr.c
diff -u src/lib/libc/stdio/fgetstr.c:1.11 src/lib/libc/stdio/fgetstr.c:1.12
--- src/lib/libc/stdio/fgetstr.c:1.11	Mon Jan 11 20:39:29 2010
+++ src/lib/libc/stdio/fgetstr.c	Thu Jun  8 15:59:45 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fgetstr.c,v 1.11 2010/01/11 20:39:29 joerg Exp $	*/
+/* $NetBSD: fgetstr.c,v 1.12 2017/06/08 15:59:45 uwe Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: fgetstr.c,v 1.11 2010/01/11 20:39:29 joerg Exp $");
+__RCSID("$NetBSD: fgetstr.c,v 1.12 2017/06/08 15:59:45 uwe Exp $");
 
 #include "namespace.h"
 
@@ -43,7 +43,7 @@ __RCSID("$NetBSD: fgetstr.c,v 1.11 2010/
 /*
  * Get an input line.
  * This now uses getdelim(3) for a code reduction.
- * The upside is that strings are now always NULL terminated, but relying
+ * The upside is that strings are now always null-terminated, but relying
  * on this is non portable - better to use the POSIX getdelim(3) function.
  */
 char *

Index: src/lib/libc/stdio/getdelim.c
diff -u src/lib/libc/stdio/getdelim.c:1.13 src/lib/libc/stdio/getdelim.c:1.14
--- src/lib/libc/stdio/getdelim.c:1.13	Fri Jul 22 23:12:30 2011
+++ src/lib/libc/stdio/getdelim.c	Thu Jun  8 15:59:45 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
+/* $NetBSD: getdelim.c,v 1.14 2017/06/08 15:59:45 uwe Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $");
+__RCSID("$NetBSD: getdelim.c,v 1.14 2017/06/08 15:59:45 uwe Exp $");
 
 #include "namespace.h"
 
@@ -96,7 +96,7 @@ __getdelim(char **__restrict buf, size_t
 			errno = EOVERFLOW;
 			goto error;
 		}
-		newlen++; /* reserve space for the NULL terminator */
+		newlen++; /* reserve space for the null terminator */
 		if (newlen > *buflen) {
 			if (newlen < MINBUF)
 newlen = MINBUF;



CVS commit: src/lib/libc/stdio

2017-02-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Feb 22 15:08:55 UTC 2017

Modified Files:
src/lib/libc/stdio: putc.3

Log Message:
Add reference to flockfile(3) in SEE ALSO section.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.12 src/lib/libc/stdio/putc.3:1.13
--- src/lib/libc/stdio/putc.3:1.12	Thu May  6 09:01:34 2010
+++ src/lib/libc/stdio/putc.3	Wed Feb 22 15:08:55 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: putc.3,v 1.12 2010/05/06 09:01:34 jruoho Exp $
+.\"	$NetBSD: putc.3,v 1.13 2017/02/22 15:08:55 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -133,6 +133,7 @@ a write error occurs,
 or if an attempt is made to write a read-only stream.
 .Sh SEE ALSO
 .Xr ferror 3 ,
+.Xr flockfile 3 ,
 .Xr fopen 3 ,
 .Xr getc 3 ,
 .Xr stdio 3



CVS commit: src/lib/libc/stdio

2017-02-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Feb 22 14:58:33 UTC 2017

Modified Files:
src/lib/libc/stdio: fputs.3

Log Message:
Fix a sentence.
Add write(2) in SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 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.11 src/lib/libc/stdio/fputs.3:1.12
--- src/lib/libc/stdio/fputs.3:1.11	Thu Aug  7 16:43:24 2003
+++ src/lib/libc/stdio/fputs.3	Wed Feb 22 14:58:33 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fputs.3,v 1.11 2003/08/07 16:43:24 agc Exp $
+.\"	$NetBSD: fputs.3,v 1.12 2017/02/22 14:58:33 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -92,9 +92,10 @@ and
 .Fn puts
 may also fail and set
 .Va errno
-for any of the errors specified for the routines
+for any of the errors specified for the routine
 .Xr write 2 .
 .Sh SEE ALSO
+.Xr write 2 ,
 .Xr ferror 3 ,
 .Xr putc 3 ,
 .Xr stdio 3



CVS commit: src/lib/libc/stdio

2017-02-21 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Tue Feb 21 18:47:40 UTC 2017

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
Insert comma between two Nm entries.
Replace Nm with Fn to refer a function.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/lib/libc/stdio/printf.3:1.66
--- src/lib/libc/stdio/printf.3:1.65	Thu Nov 19 10:03:26 2015
+++ src/lib/libc/stdio/printf.3	Tue Feb 21 18:47:40 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: printf.3,v 1.65 2015/11/19 10:03:26 pgoyette Exp $
+.\"	$NetBSD: printf.3,v 1.66 2017/02/21 18:47:40 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -39,7 +39,7 @@
 .Sh NAME
 .Nm printf ,
 .Nm fprintf ,
-.Nm dprintf
+.Nm dprintf ,
 .Nm sprintf ,
 .Nm snprintf ,
 .Nm snprintf_ss ,
@@ -937,7 +937,7 @@ conversions, as well as other nonsensica
 are not standard; such combinations should be avoided.
 .Pp
 The
-.Nm
+.Fn printf
 family of functions do not correctly handle multibyte characters in the
 .Fa format
 argument.



CVS commit: src/lib/libc/stdio

2017-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 10 17:45:12 UTC 2017

Modified Files:
src/lib/libc/stdio: gettemp.c vdprintf.c

Log Message:
include 


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdio/gettemp.c
cvs rdiff -u -r1.4 -r1.5 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/gettemp.c
diff -u src/lib/libc/stdio/gettemp.c:1.20 src/lib/libc/stdio/gettemp.c:1.21
--- src/lib/libc/stdio/gettemp.c:1.20	Thu Feb  5 11:05:20 2015
+++ src/lib/libc/stdio/gettemp.c	Tue Jan 10 12:45:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: gettemp.c,v 1.20 2015/02/05 16:05:20 christos Exp $	*/
+/*	$NetBSD: gettemp.c,v 1.21 2017/01/10 17:45:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -38,11 +38,12 @@
 #if 0
 static char sccsid[] = "@(#)mktemp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: gettemp.c,v 1.20 2015/02/05 16:05:20 christos Exp $");
+__RCSID("$NetBSD: gettemp.c,v 1.21 2017/01/10 17:45:12 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
 #include 
+#include 
 #include 
 #include 
 

Index: src/lib/libc/stdio/vdprintf.c
diff -u src/lib/libc/stdio/vdprintf.c:1.4 src/lib/libc/stdio/vdprintf.c:1.5
--- src/lib/libc/stdio/vdprintf.c:1.4	Fri May 17 08:55:57 2013
+++ src/lib/libc/stdio/vdprintf.c	Tue Jan 10 12:45:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vdprintf.c,v 1.4 2013/05/17 12:55:57 joerg Exp $	*/
+/*	$NetBSD: vdprintf.c,v 1.5 2017/01/10 17:45:12 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,11 +34,12 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vdprintf.c,v 1.4 2013/05/17 12:55:57 joerg Exp $");
+__RCSID("$NetBSD: vdprintf.c,v 1.5 2017/01/10 17:45:12 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
 #include 
+#include 
 
 #include 
 #include 



CVS commit: src/lib/libc/stdio

2017-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 10 17:44:28 UTC 2017

Modified Files:
src/lib/libc/stdio: fseeko.c

Log Message:
add linted comment


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/fseeko.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/fseeko.c
diff -u src/lib/libc/stdio/fseeko.c:1.13 src/lib/libc/stdio/fseeko.c:1.14
--- src/lib/libc/stdio/fseeko.c:1.13	Sun Oct 19 07:17:43 2014
+++ src/lib/libc/stdio/fseeko.c	Tue Jan 10 12:44:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fseeko.c,v 1.13 2014/10/19 11:17:43 justin Exp $	*/
+/*	$NetBSD: fseeko.c,v 1.14 2017/01/10 17:44:28 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fseeko.c,v 1.13 2014/10/19 11:17:43 justin Exp $");
+__RCSID("$NetBSD: fseeko.c,v 1.14 2017/01/10 17:44:28 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -130,6 +130,7 @@ fseeko(FILE *fp, off_t offset, int whenc
 			FUNLOCKFILE(fp);
 			return -1;
 		}
+		/*FALLTHROUGH*/
 	case SEEK_END:
 		curoff = 0;		/* XXX just to keep gcc quiet */
 		havepos = 0;



CVS commit: src/lib/libc/stdio

2017-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 10 17:00:58 UTC 2017

Modified Files:
src/lib/libc/stdio: fdopen.c

Log Message:
Need 


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/fdopen.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/fdopen.c
diff -u src/lib/libc/stdio/fdopen.c:1.16 src/lib/libc/stdio/fdopen.c:1.17
--- src/lib/libc/stdio/fdopen.c:1.16	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/fdopen.c	Tue Jan 10 12:00:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdopen.c,v 1.16 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: fdopen.c,v 1.17 2017/01/10 17:00:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,12 +37,14 @@
 #if 0
 static char sccsid[] = "@(#)fdopen.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fdopen.c,v 1.16 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: fdopen.c,v 1.17 2017/01/10 17:00:58 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
+
 #include 
+#include 
 
 #include 
 #include 



CVS commit: src/lib/libc/stdio

2017-01-01 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Jan  1 12:39:33 UTC 2017

Modified Files:
src/lib/libc/stdio: fseek.3

Log Message:
Fix sentences at a couple of places.
Reorganize the RETURN VALUES section a bit to improve readability.
Add xrefs to clearerr(3) and ungetc(3) in SEE ALSO.
Bump date.

ok wiz@


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/lib/libc/stdio/fseek.3:1.28
--- src/lib/libc/stdio/fseek.3:1.27	Sun Jan 22 19:13:42 2012
+++ src/lib/libc/stdio/fseek.3	Sun Jan  1 12:39:33 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fseek.3,v 1.27 2012/01/22 19:13:42 wiz Exp $
+.\"	$NetBSD: fseek.3,v 1.28 2017/01/01 12:39:33 abhinav 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 21, 2012
+.Dd January 1, 2017
 .Dt FSEEK 3
 .Os
 .Sh NAME
@@ -127,10 +127,10 @@ except that the error indicator for the 
 (see
 .Xr clearerr 3 ) .
 .Pp
-In this implementations, an
+In this implementations,
 .Dq Fa fpos_t
-object is a complex object that represents both the position and the parse
-state of the stream making these routines are the only way to portably
+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
 reposition a text stream.
 The
 .Ar pos
@@ -144,32 +144,34 @@ The
 .Fn rewind
 function
 returns no value.
+.Pp
 Upon successful completion,
 .Fn fgetpos ,
 .Fn fseek ,
 .Fn fseeko ,
 and
 .Fn fsetpos
-return 0.
-The functions
+return 0,
+whereas the functions
 .Fn ftell
 and
 .Fn ftello
 return the current offset.
-Otherwise,
+On failure,
 .Fn fseek ,
 .Fn fseeko ,
 .Fn ftell ,
 and
 .Fn ftello
-return \-1 while
+return \-1, while
 .Fn fgetpos
 and
 .Fn fsetpos
 return a nonzero value.
-On error all functions the global variable
+.Pp
+On error all functions set the global variable
 .Va errno
-is set to indicate the error.
+to indicate the error.
 Since the
 .Fn rewind
 function does not return an error code, applications need to clear
@@ -217,7 +219,9 @@ for any of the errors specified for the 
 and
 .Xr malloc 3 .
 .Sh SEE ALSO
-.Xr lseek 2
+.Xr lseek 2 ,
+.Xr clearerr 3 ,
+.Xr ungetc 3
 .Sh STANDARDS
 The
 .Fn fgetpos ,



CVS commit: src/lib/libc/stdio

2016-12-29 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Dec 29 20:29:30 UTC 2016

Modified Files:
src/lib/libc/stdio: printf_l.3

Log Message:
Mention stdarg.h for va_list.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdio/printf_l.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_l.3
diff -u src/lib/libc/stdio/printf_l.3:1.1 src/lib/libc/stdio/printf_l.3:1.2
--- src/lib/libc/stdio/printf_l.3:1.1	Tue Dec 29 17:55:23 2015
+++ src/lib/libc/stdio/printf_l.3	Thu Dec 29 20:29:30 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: printf_l.3,v 1.1 2015/12/29 17:55:23 christos Exp $
+.\"	$NetBSD: printf_l.3,v 1.2 2016/12/29 20:29:30 wiz Exp $
 .\" Copyright (c) 2012 Isabell Long 
 .\" All rights reserved.
 .\"
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD: head/lib/libc/stdio/printf_l.3 258245 2013-11-17 02:03:45Z eadler $
 .\"
-.Dd December 29, 2015
+.Dd December 29, 2016
 .Dt PRINTF_L 3
 .Os
 .Sh NAME
@@ -55,6 +55,7 @@
 .Fn snprintf_l "char * restrict str" "size_t size" "locale_t loc" "const char * restrict format" "..."
 .Ft int
 .Fn sprintf_l "char * restrict str" "locale_t loc" "const char * restrict format" "..."
+.In stdarg.h
 .Ft int
 .Fn vasprintf_l "char **ret" "locale_t loc" "const char *format" "va_list ap"
 .Ft int



CVS commit: src/lib/libc/stdio

2016-10-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 23 21:01:52 UTC 2016

Modified Files:
src/lib/libc/stdio: funopen.c

Log Message:
PR/51572: calling funopen on each printw call is a tad excessive, but this
is not a reason for funopen to leak. Always call the close function since we
are indirecting through our cookie and we need to free it.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdio/funopen.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/funopen.c
diff -u src/lib/libc/stdio/funopen.c:1.14 src/lib/libc/stdio/funopen.c:1.15
--- src/lib/libc/stdio/funopen.c:1.14	Wed Mar 28 11:21:11 2012
+++ src/lib/libc/stdio/funopen.c	Sun Oct 23 17:01:52 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: funopen.c,v 1.14 2012/03/28 15:21:11 christos Exp $	*/
+/*	$NetBSD: funopen.c,v 1.15 2016/10/23 21:01:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)funopen.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: funopen.c,v 1.14 2012/03/28 15:21:11 christos Exp $");
+__RCSID("$NetBSD: funopen.c,v 1.15 2016/10/23 21:01:52 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -138,6 +138,8 @@ cclosefn(void *dookie)
 	void *c = d->cookie;
 	int (*cf)(void *) = d->closefn;
 	free(dookie);
+	if (cf == NULL)
+		return 0;
 	return (*cf)(c);
 }
 
@@ -163,8 +165,7 @@ funopen(const void *cookie,
 	d->readfn ? creadfn : NULL,
 	d->writefn ? cwritefn : NULL,
 	d->seekfn ? cseekfn : NULL,
-	NULL,
-	d->closefn ? cclosefn : NULL);
+	NULL, cclosefn);
 	if (fp != NULL)
 		return fp;
 	free(d);



CVS commit: src/lib/libc/stdio

2016-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 27 13:15:48 UTC 2016

Modified Files:
src/lib/libc/stdio: fgetwln.c

Log Message:
Improvements to fgetwln(3) from Andrey Chernov:

1) Set the stdio error indicator on __slbexpand() failure.

2) fgetwc(3) may succeed even when ferror(3) is already set
   (for example, consider a program using SIG_IGN on SIGTTIN,
   reading from the tty while in the background, getting EIO,
   then coming to the foreground and reading again).
   So do not force fgetwln(3) to fail in such a case either.
   (Yes, the program should probably clearerr(3) before
   reading again, but let's be nicer in case it forgets.)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdio/fgetwln.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/fgetwln.c
diff -u src/lib/libc/stdio/fgetwln.c:1.7 src/lib/libc/stdio/fgetwln.c:1.8
--- src/lib/libc/stdio/fgetwln.c:1.7	Mon Aug 22 03:41:10 2016
+++ src/lib/libc/stdio/fgetwln.c	Sat Aug 27 09:15:48 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fgetwln.c,v 1.7 2016/08/22 07:41:10 christos Exp $	*/
+/*	$NetBSD: fgetwln.c,v 1.8 2016/08/27 13:15:48 christos Exp $	*/
 
 /*-
  * Copyright (c) 2002-2004 Tim J. Robbins.
@@ -31,7 +31,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwln.c,v 1.2 2004/08/06 17:00:09 tjr Exp $");
 #else
-__RCSID("$NetBSD: fgetwln.c,v 1.7 2016/08/22 07:41:10 christos Exp $");
+__RCSID("$NetBSD: fgetwln.c,v 1.8 2016/08/27 13:15:48 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -88,13 +88,25 @@ fgetwln(FILE * __restrict fp, size_t *le
 	while ((wc = __fgetwc_unlock(fp)) != WEOF) {
 #define	GROW	512
 		if (len * sizeof(wchar_t) >= _EXT(fp)->_fgetstr_len &&
-		__slbexpand(fp, (len + GROW) * sizeof(wchar_t)))
+		__slbexpand(fp, (len + GROW) * sizeof(wchar_t))) {
+			fp->_flags |= __SERR;
 			goto error;
+		}
 		*((wchar_t *)(void *)_EXT(fp)->_fgetstr_buf + len++) = wc;
 		if (wc == L'\n')
 			break;
 	}
-	if (len == 0 || fp->_flags & __SERR)
+
+	/*
+	 * The following test assumes that fgetwc() fails when
+	 * feof() is already set, and that fgetwc() will never
+	 * set feof() in the same call where it also sets ferror()
+	 * or returns non-WEOF.
+	 * Testing ferror() would not be better because fgetwc()
+	 * may succeed even when ferror() is already set.
+	 */
+
+	if (len == 0 || (wc == WEOF && !__sfeof(fp)))
 		goto error;
 
 	FUNLOCKFILE(fp);



CVS commit: src/lib/libc/stdio

2016-08-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 22 07:41:10 UTC 2016

Modified Files:
src/lib/libc/stdio: fgetwln.c

Log Message:
missing _


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdio/fgetwln.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/fgetwln.c
diff -u src/lib/libc/stdio/fgetwln.c:1.6 src/lib/libc/stdio/fgetwln.c:1.7
--- src/lib/libc/stdio/fgetwln.c:1.6	Mon Aug 22 02:11:39 2016
+++ src/lib/libc/stdio/fgetwln.c	Mon Aug 22 03:41:10 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fgetwln.c,v 1.6 2016/08/22 06:11:39 christos Exp $	*/
+/*	$NetBSD: fgetwln.c,v 1.7 2016/08/22 07:41:10 christos Exp $	*/
 
 /*-
  * Copyright (c) 2002-2004 Tim J. Robbins.
@@ -31,7 +31,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwln.c,v 1.2 2004/08/06 17:00:09 tjr Exp $");
 #else
-__RCSID("$NetBSD: fgetwln.c,v 1.6 2016/08/22 06:11:39 christos Exp $");
+__RCSID("$NetBSD: fgetwln.c,v 1.7 2016/08/22 07:41:10 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -94,7 +94,7 @@ fgetwln(FILE * __restrict fp, size_t *le
 		if (wc == L'\n')
 			break;
 	}
-	if (len == 0 || fp->flags & __SERR)
+	if (len == 0 || fp->_flags & __SERR)
 		goto error;
 
 	FUNLOCKFILE(fp);



CVS commit: src/lib/libc/stdio

2016-08-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 22 06:11:39 UTC 2016

Modified Files:
src/lib/libc/stdio: fgetwln.c

Log Message:
>From OpenBSD:
bugfix: when fgetwc(3) fails, fgetwln(3) must fail as well;


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdio/fgetwln.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/fgetwln.c
diff -u src/lib/libc/stdio/fgetwln.c:1.5 src/lib/libc/stdio/fgetwln.c:1.6
--- src/lib/libc/stdio/fgetwln.c:1.5	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/fgetwln.c	Mon Aug 22 02:11:39 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fgetwln.c,v 1.5 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: fgetwln.c,v 1.6 2016/08/22 06:11:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 2002-2004 Tim J. Robbins.
@@ -31,7 +31,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwln.c,v 1.2 2004/08/06 17:00:09 tjr Exp $");
 #else
-__RCSID("$NetBSD: fgetwln.c,v 1.5 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: fgetwln.c,v 1.6 2016/08/22 06:11:39 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -94,7 +94,7 @@ fgetwln(FILE * __restrict fp, size_t *le
 		if (wc == L'\n')
 			break;
 	}
-	if (len == 0)
+	if (len == 0 || fp->flags & __SERR)
 		goto error;
 
 	FUNLOCKFILE(fp);



CVS commit: src/lib/libc/stdio

2016-04-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Apr  6 03:38:31 UTC 2016

Modified Files:
src/lib/libc/stdio: funopen.3

Log Message:
improve usage


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 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.23 src/lib/libc/stdio/funopen.3:1.24
--- src/lib/libc/stdio/funopen.3:1.23	Sun Sep  6 01:36:21 2015
+++ src/lib/libc/stdio/funopen.3	Wed Apr  6 03:38:31 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: funopen.3,v 1.23 2015/09/06 01:36:21 dholland Exp $
+.\"	$NetBSD: funopen.3,v 1.24 2016/04/06 03:38:31 dholland Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -79,9 +79,9 @@ close the new stream.
 The
 .Fn funopen2
 function provides sightly different read and write signatures, which match
-better the corresponding system calls, plus the ability to augment the
-streams default flushing function.
-If a flushing function is provided, then it is called after all data has
+the corresponding system calls better, plus the ability to augment the
+stream's default flushing function.
+If a flushing function is provided, it is called after all data has
 been written to the stream.
 .Pp
 In general, omitting a function means that any attempt to perform the



CVS commit: src/lib/libc/stdio

2015-12-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec 29 17:55:23 UTC 2015

Modified Files:
src/lib/libc/stdio: Makefile.inc
Added Files:
src/lib/libc/stdio: printf_l.3 scanf_l.3

Log Message:
Add printf/scanf man pages from FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/lib/libc/stdio/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/stdio/printf_l.3 \
src/lib/libc/stdio/scanf_l.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/Makefile.inc
diff -u src/lib/libc/stdio/Makefile.inc:1.46 src/lib/libc/stdio/Makefile.inc:1.47
--- src/lib/libc/stdio/Makefile.inc:1.46	Sun Oct 12 20:40:36 2014
+++ src/lib/libc/stdio/Makefile.inc	Tue Dec 29 12:55:23 2015
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	5.7 (Berkeley) 6/27/91
-#	$NetBSD: Makefile.inc,v 1.46 2014/10/13 00:40:36 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.47 2015/12/29 17:55:23 christos Exp $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
@@ -30,8 +30,8 @@ SRCS+=	gets.c vsprintf.c tempnam.c tmpna
 MAN+=	fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
 	flockfile.3 fmemopen.3 fopen.3 fparseln.3 fputs.3 fputws.3 fread.3 \
 	fseek.3 funopen.3 fwide.3 getc.3 getdelim.3 getwc.3 mktemp.3 printf.3 \
-	putc.3 putwc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 \
-	ungetc.3 ungetwc.3 wprintf.3 wscanf.3 open_memstream.3
+	printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 stdio.3 \
+	tmpnam.3 ungetc.3 ungetwc.3 wprintf.3 wscanf.3 open_memstream.3
 
 MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
 MLINKS+=fflush.3 fpurge.3
@@ -67,3 +67,10 @@ MLINKS+=wprintf.3 vwprintf.3 wprintf.3 v
 MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3
 MLINKS+=wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3
 MLINKS+=open_memstream.3 open_wmemstream.3
+MLINKS+=printf_l.3 asprintf_l.3 printf_l.3 fprintf_l.3 printf_l.3 snprintf_l.3 \
+printf_l.3 sprintf_l.3 printf_l.3 vasprintf_l.3 printf_l.3  \
+	vfprintf_l.3 printf_l.3 vprintf_l.3 printf_l.3 vsnprintf_l.3 \
+	printf_l.3 vsprintf_l.3
+MLINKS+=scanf_l.3 fscanf_l.3 scanf_l.3 sscanf_l.3 scanf_l.3 vfscanf_l.3 \
+scanf_l.3 vscanf_l.3 scanf_l.3 vsscanf_l.3
+

Added files:

Index: src/lib/libc/stdio/printf_l.3
diff -u /dev/null src/lib/libc/stdio/printf_l.3:1.1
--- /dev/null	Tue Dec 29 12:55:23 2015
+++ src/lib/libc/stdio/printf_l.3	Tue Dec 29 12:55:23 2015
@@ -0,0 +1,84 @@
+.\"	$NetBSD: printf_l.3,v 1.1 2015/12/29 17:55:23 christos Exp $
+.\" Copyright (c) 2012 Isabell Long 
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: head/lib/libc/stdio/printf_l.3 258245 2013-11-17 02:03:45Z eadler $
+.\"
+.Dd December 29, 2015
+.Dt PRINTF_L 3
+.Os
+.Sh NAME
+.Nm printf_l ,
+.Nm asprintf_l ,
+.Nm fprintf_l ,
+.Nm snprintf_l ,
+.Nm sprintf_l ,
+.Nm vasprintf_l ,
+.Nm vfprintf_l ,
+.Nm vprintf_l ,
+.Nm vsnprintf_l ,
+.Nm vsprintf_l
+.Nd formatted output conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In locale.h
+.Ft int
+.Fn printf_l "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn asprintf_l "char **ret" "locale_t loc" "const char * format" "..."
+.Ft int
+.Fn fprintf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn snprintf_l "char * restrict str" "size_t size" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn sprintf_l "char * restrict str" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn vasprintf_l "char **ret" "locale_t loc" "const char *format" "va_list ap"
+.Ft int
+.Fn vfprintf_l "FILE * 

CVS commit: src/lib/libc/stdio

2015-11-19 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Nov 19 10:03:26 UTC 2015

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
Remove duplicated 'i' from list of numeric formats


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.64 src/lib/libc/stdio/printf.3:1.65
--- src/lib/libc/stdio/printf.3:1.64	Mon Sep 29 14:58:33 2014
+++ src/lib/libc/stdio/printf.3	Thu Nov 19 10:03:26 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: printf.3,v 1.64 2014/09/29 14:58:33 christos Exp $
+.\"	$NetBSD: printf.3,v 1.65 2015/11/19 10:03:26 pgoyette 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 September 29, 2014
+.Dd November 19, 2015
 .Dt PRINTF 3
 .Os
 .Sh NAME
@@ -279,7 +279,6 @@ If a precision is given with a numeric c
 .Cm i ,
 .Cm o ,
 .Cm u ,
-.Cm i ,
 .Cm x ,
 and
 .Cm X ) ,



CVS commit: src/lib/libc/stdio

2015-09-05 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Sep  6 03:10:50 UTC 2015

Modified Files:
src/lib/libc/stdio: fmemopen.3

Log Message:
English grammar nit: there's only one function described in this man page


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdio/fmemopen.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/fmemopen.3
diff -u src/lib/libc/stdio/fmemopen.3:1.8 src/lib/libc/stdio/fmemopen.3:1.9
--- src/lib/libc/stdio/fmemopen.3:1.8	Sun Sep  6 01:37:35 2015
+++ src/lib/libc/stdio/fmemopen.3	Sun Sep  6 03:10:50 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fmemopen.3,v 1.8 2015/09/06 01:37:35 dholland Exp $
+.\"	$NetBSD: fmemopen.3,v 1.9 2015/09/06 03:10:50 pgoyette Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -190,5 +190,5 @@ function conforms to
 .Sh HISTORY
 The
 .Fn fmemopen
-functions first appeared in
+function first appeared in
 .Nx 6.0 .



CVS commit: src/lib/libc/stdio

2015-09-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Sep  6 01:35:35 UTC 2015

Modified Files:
src/lib/libc/stdio: stdio.3

Log Message:
Mention fmemopen().


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 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.24 src/lib/libc/stdio/stdio.3:1.25
--- src/lib/libc/stdio/stdio.3:1.24	Wed May  5 04:13:16 2010
+++ src/lib/libc/stdio/stdio.3	Sun Sep  6 01:35:34 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stdio.3,v 1.24 2010/05/05 04:13:16 jruoho Exp $
+.\"	$NetBSD: stdio.3,v 1.25 2015/09/06 01:35:34 dholland Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -241,6 +241,7 @@ library conforms to
 .It fgetwc	get next wide character from input stream
 .It fileno	check and reset stream status
 .It flockfile	lock a stream
+.It fmemopen	open a stream that points to a memory buffer
 .It fopen	stream open functions
 .It fprintf	formatted output conversion
 .It fpurge	flush a stream



CVS commit: src/lib/libc/stdio

2015-09-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Sep  6 01:37:35 UTC 2015

Modified Files:
src/lib/libc/stdio: fmemopen.3

Log Message:
Improve the short description.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdio/fmemopen.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/fmemopen.3
diff -u src/lib/libc/stdio/fmemopen.3:1.7 src/lib/libc/stdio/fmemopen.3:1.8
--- src/lib/libc/stdio/fmemopen.3:1.7	Mon Oct  8 18:15:09 2012
+++ src/lib/libc/stdio/fmemopen.3	Sun Sep  6 01:37:35 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fmemopen.3,v 1.7 2012/10/08 18:15:09 njoly Exp $
+.\"	$NetBSD: fmemopen.3,v 1.8 2015/09/06 01:37:35 dholland Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -30,12 +30,12 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 15, 2011
+.Dd September 5, 2015
 .Dt FMEMOPEN 3
 .Os
 .Sh NAME
 .Nm fmemopen
-.Nd open a stream that points to the given buffer
+.Nd open a stream that points to a memory buffer
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS



CVS commit: src/lib/libc/stdio

2015-09-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Sep  6 01:36:21 UTC 2015

Modified Files:
src/lib/libc/stdio: funopen.3

Log Message:
SEE ALSO fmemopen(3)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.22 src/lib/libc/stdio/funopen.3:1.23
--- src/lib/libc/stdio/funopen.3:1.22	Mon Oct  8 18:15:09 2012
+++ src/lib/libc/stdio/funopen.3	Sun Sep  6 01:36:21 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: funopen.3,v 1.22 2012/10/08 18:15:09 njoly Exp $
+.\"	$NetBSD: funopen.3,v 1.23 2015/09/06 01:36:21 dholland Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -169,6 +169,7 @@ specified for the routine
 .Xr fcntl 2 ,
 .Xr open 2 ,
 .Xr fclose 3 ,
+.Xr fmemopen 3 ,
 .Xr fopen 3 ,
 .Xr fseek 3 ,
 .Xr setbuf 3



CVS commit: src/lib/libc/stdio

2015-09-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Sep  6 04:20:50 UTC 2015

Modified Files:
src/lib/libc/stdio: stdio.3

Log Message:
add a bunch of functions found in  that weren't listed here.
(this list may still be incomplete.)


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 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.25 src/lib/libc/stdio/stdio.3:1.26
--- src/lib/libc/stdio/stdio.3:1.25	Sun Sep  6 01:35:34 2015
+++ src/lib/libc/stdio/stdio.3	Sun Sep  6 04:20:50 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stdio.3,v 1.25 2015/09/06 01:35:34 dholland Exp $
+.\"	$NetBSD: stdio.3,v 1.26 2015/09/06 04:20:50 mrg 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 May 5, 2010
+.Dd September 6, 2015
 .Dt STDIO 3
 .Os
 .Sh NAME
@@ -228,7 +228,11 @@ library conforms to
 .Sh LIST OF FUNCTIONS
 .Bl -column "putchar_unlocked" "Description"
 .It Sy Function	Description
+.It asprintf	formatted output conversion with allocation
+.It asprintf_l	formatted output conversion with allocation
 .It clearerr	check and reset stream status
+.It dprintf	formatted output conversion
+.It dprintf_l	formatted output conversion
 .It fclose	close a stream
 .It fdopen	stream open functions
 .It feof	check and reset stream status
@@ -244,6 +248,7 @@ library conforms to
 .It fmemopen	open a stream that points to a memory buffer
 .It fopen	stream open functions
 .It fprintf	formatted output conversion
+.It fprintf_l	formatted output conversion
 .It fpurge	flush a stream
 .It fputc	output a character or word to a stream
 .It fputs	output a line to a stream
@@ -252,12 +257,16 @@ library conforms to
 .It freopen	stream open functions
 .It fropen	open a stream
 .It fscanf	input format conversion
+.It fscanf_l	input format conversion
 .It fseek	reposition a stream
+.It fseeko	reposition a stream
 .It fsetpos	reposition a stream
 .It ftell	reposition a stream
+.It ftello	reposition a stream
 .It ftrylockfile	lock a stream (non-blocking)
 .It funlockfile	unlock a stream
 .It funopen	open a stream
+.It funopen2	open a stream, with flush support
 .It fwide	set/get orientation of a stream
 .It fwopen	open a stream
 .It fwrite	binary stream input/output
@@ -275,8 +284,13 @@ library conforms to
 .It getwchar	get next wide character from input stream
 .It mkstemp	create unique temporary file
 .It mktemp	create unique temporary file
+.It open_memstream	open memory as a stream
+.It popen	open a program as a stream
+.It popenve	open a program as a stream
+.It pclose	close an opened program stream
 .It perror	system error messages
 .It printf	formatted output conversion
+.It printf_l	formatted output conversion
 .It putc	output a character or word to a stream
 .It putc_unlocked	output a character or word to a stream
 .It Ta (no implicit locking)
@@ -290,13 +304,16 @@ library conforms to
 .It remove	remove directory entry
 .It rewind	reposition a stream
 .It scanf	input format conversion
+.It scanf_l	input format conversion
 .It setbuf	stream buffering operations
 .It setbuffer	stream buffering operations
 .It setlinebuf	stream buffering operations
 .It setvbuf	stream buffering operations
 .It snprintf	formatted output conversion
+.It snprintf_l	formatted output conversion
 .It sprintf	formatted output conversion
 .It sscanf	input format conversion
+.It sscanf_l	input format conversion
 .It strerror	system error messages
 .It sys_errlist	system error messages
 .It sys_nerr	system error messages
@@ -305,13 +322,24 @@ library conforms to
 .It tmpnam	temporary file routines
 .It ungetc	un-get character from input stream
 .It ungetwc	un-get wide character from input stream
+.It vasprintf	formatted output conversion with allocation
+.It vasprintf_l	formatted output conversion with allocation
+.It vdprintf	formatted output conversion
+.It vdprintf_l	formatted output conversion
 .It vfprintf	formatted output conversion
+.It vfprintf_l	formatted output conversion
 .It vfscanf	input format conversion
+.It vfscanf_l	input format conversion
 .It vprintf	formatted output conversion
+.It vprintf_l	formatted output conversion
 .It vscanf	input format conversion
+.It vscanf_l	input format conversion
 .It vsnprintf	formatted output conversion
+.It vsnprintf_l	formatted output conversion
 .It vsprintf	formatted output conversion
+.It vsprintf_l	formatted output conversion
 .It vsscanf	input format conversion
+.It vsscanf_l	input format conversion
 .El
 .Sh BUGS
 The standard buffered functions do not interact well with certain other



CVS commit: src/lib/libc/stdio

2015-07-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 15 19:08:43 UTC 2015

Modified Files:
src/lib/libc/stdio: fopen.3 makebuf.c setbuf.3

Log Message:
Allow changing the default buffering policy for a stdio stream during
construction by setting environment variables.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdio/fopen.3
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/makebuf.c
cvs rdiff -u -r1.13 -r1.14 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/fopen.3
diff -u src/lib/libc/stdio/fopen.3:1.30 src/lib/libc/stdio/fopen.3:1.31
--- src/lib/libc/stdio/fopen.3:1.30	Wed Feb 11 10:19:05 2015
+++ src/lib/libc/stdio/fopen.3	Wed Jul 15 15:08:43 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: fopen.3,v 1.30 2015/02/11 15:19:05 riastradh Exp $
+.\	$NetBSD: fopen.3,v 1.31 2015/07/15 19:08:43 christos Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -196,6 +196,13 @@ standard text stream
 .Em stdin ,
 or
 .Em stdout ) .
+.Pp
+Input and output against the opened stream will be fully buffered, unless
+it refers to an interactive terminal device, or a different kind of buffering
+is specified in the environment.
+See
+.Xr setvbuf 3
+for additional details.
 .Sh RETURN VALUES
 Upon successful completion
 .Fn fopen ,

Index: src/lib/libc/stdio/makebuf.c
diff -u src/lib/libc/stdio/makebuf.c:1.17 src/lib/libc/stdio/makebuf.c:1.18
--- src/lib/libc/stdio/makebuf.c:1.17	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/makebuf.c	Wed Jul 15 15:08:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: makebuf.c,v 1.17 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: makebuf.c,v 1.18 2015/07/15 19:08:43 christos 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.17 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: makebuf.c,v 1.18 2015/07/15 19:08:43 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -49,10 +49,64 @@ __RCSID($NetBSD: makebuf.c,v 1.17 2012/
 #include stdio.h
 #include stdlib.h
 #include unistd.h
+#include inttypes.h
+#include ctype.h
 #include reentrant.h
 #include local.h
 
 /*
+ * Override the file buffering based on the environment setting STDBUF%d
+ * (for the specific file descriptor) and STDBUF (for all descriptors).
+ * the setting is ULBnum standing for Unbuffered, Linebuffered,
+ * and Fullybuffered, and num is a value from 0 to 1M.
+ */
+static int
+__senvbuf(FILE *fp, size_t *size, int *couldbetty)
+{
+	char evb[64], *evp;
+	int flags, e;
+	intmax_t s;
+
+	flags = 0;
+	if (snprintf(evb, sizeof(evb), STDBUF%d, fp-_file)  0)
+		return flags;
+
+	if ((evp = getenv(evb)) == NULL  (evp = getenv(STDBUF)) == NULL)
+		return flags;
+
+	switch (*evp) {
+	case 'u':
+	case 'U':
+		evp++;
+		flags |= __SNBF;
+		break;
+	case 'l':
+	case 'L':
+		evp++;
+		flags |= __SLBF;
+		break;
+	case 'f':
+	case 'F':
+		evp++;
+		*couldbetty = 0;
+		break;
+	}
+
+	if (!isdigit((unsigned char)*evp))
+		return flags;
+
+	s = strtoi(evp, NULL, 0, 0, 1024 * 1024, e);
+	if (e != 0)
+		return flags;
+
+	*size = (size_t)s;
+	if (*size == 0)
+		return __SNBF;
+
+	return flags;
+}
+
+/*
  * Allocate a file buffer, or switch to unbuffered I/O.
  * Per the ANSI C standard, ALL tty devices default to line buffered.
  *
@@ -69,18 +123,21 @@ __smakebuf(FILE *fp)
 
 	_DIAGASSERT(fp != NULL);
 
-	if (fp-_flags  __SNBF) {
-		fp-_bf._base = fp-_p = fp-_nbuf;
-		fp-_bf._size = 1;
-		return;
-	}
+	if (fp-_flags  __SNBF)
+		goto unbuf;
+
 	flags = __swhatbuf(fp, size, couldbetty);
-	if ((p = malloc(size)) == NULL) {
-		fp-_flags |= __SNBF;
-		fp-_bf._base = fp-_p = fp-_nbuf;
-		fp-_bf._size = 1;
-		return;
+
+	if ((fp-_flags  (__SLBF|__SNBF|__SMBF)) == 0
+	 fp-_cookie == fp  fp-_file = 0) {
+		flags |= __senvbuf(fp, size, couldbetty);
+		if (flags  __SNBF)
+			goto unbuf;
 	}
+
+	if ((p = malloc(size)) == NULL)
+		goto unbuf;
+
 	__cleanup = _cleanup;
 	flags |= __SMBF;
 	fp-_bf._base = fp-_p = p;
@@ -89,6 +146,11 @@ __smakebuf(FILE *fp)
 	if (couldbetty  isatty(__sfileno(fp)))
 		flags |= __SLBF;
 	fp-_flags |= flags;
+	return;
+unbuf:
+	fp-_flags |= __SNBF;
+	fp-_bf._base = fp-_p = fp-_nbuf;
+	fp-_bf._size = 1;
 }
 
 /*

Index: src/lib/libc/stdio/setbuf.3
diff -u src/lib/libc/stdio/setbuf.3:1.13 src/lib/libc/stdio/setbuf.3:1.14
--- src/lib/libc/stdio/setbuf.3:1.13	Thu Aug  7 12:43:31 2003
+++ src/lib/libc/stdio/setbuf.3	Wed Jul 15 15:08:43 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: setbuf.3,v 1.13 2003/08/07 16:43:31 agc Exp $
+.\	$NetBSD: setbuf.3,v 1.14 2015/07/15 19:08:43 christos Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -63,6 +63,27 @@ when it is block buffered many character
 when it is line buffered 

CVS commit: src/lib/libc/stdio

2015-02-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Feb 11 15:19:05 UTC 2015

Modified Files:
src/lib/libc/stdio: fopen.3

Log Message:
Use Pq to avoid space before O_EXCL.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/lib/libc/stdio/fopen.3:1.30
--- src/lib/libc/stdio/fopen.3:1.29	Thu Nov 15 03:50:36 2012
+++ src/lib/libc/stdio/fopen.3	Wed Feb 11 15:19:05 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: fopen.3,v 1.29 2012/11/15 03:50:36 christos Exp $
+.\	$NetBSD: fopen.3,v 1.30 2015/02/11 15:19:05 riastradh Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -120,8 +120,8 @@ extension.
 .It Sq x
 The letter
 .Sq x
-in the mode turns on exclusive open mode to the file (
-.Dv O_EXCL )
+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.
 .El
 .Pp



CVS commit: src/lib/libc/stdio

2014-11-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 16 20:32:52 UTC 2014

Modified Files:
src/lib/libc/stdio: fseek.c

Log Message:
Don't try to extend the offset range on 32 bit machines by treating negative
offsets as positive. It is just confusing.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdio/fseek.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/fseek.c
diff -u src/lib/libc/stdio/fseek.c:1.23 src/lib/libc/stdio/fseek.c:1.24
--- src/lib/libc/stdio/fseek.c:1.23	Tue Apr 29 02:53:01 2008
+++ src/lib/libc/stdio/fseek.c	Sun Nov 16 15:32:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fseek.c,v 1.23 2008/04/29 06:53:01 martin Exp $	*/
+/*	$NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: fseek.c,v 1.23 2008/04/29 06:53:01 martin Exp $);
+__RCSID($NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h
@@ -55,9 +55,12 @@ fseek(FILE *fp, long l_offset, int whenc
 {
 	off_t offset;
 
+#if 0
+	/* This is a bad idea because makes fseek(fp, -6, SEEK_SET) work... */
 	if (whence == SEEK_SET)
 		offset = (unsigned long)l_offset;
 	else
+#endif
 		offset = l_offset;
 	return fseeko(fp, offset, whence);
 }



CVS commit: src/lib/libc/stdio

2014-10-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 26 14:19:28 UTC 2014

Modified Files:
src/lib/libc/stdio: open_memstream.3

Log Message:
PR/49317: Henning Petersen: Fix prototypes inman page.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdio/open_memstream.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/open_memstream.3
diff -u src/lib/libc/stdio/open_memstream.3:1.2 src/lib/libc/stdio/open_memstream.3:1.3
--- src/lib/libc/stdio/open_memstream.3:1.2	Mon Oct 13 18:41:59 2014
+++ src/lib/libc/stdio/open_memstream.3	Sun Oct 26 10:19:28 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: open_memstream.3,v 1.2 2014/10/13 22:41:59 wiz Exp $
+.\	$NetBSD: open_memstream.3,v 1.3 2014/10/26 14:19:28 christos Exp $
 .\ Copyright (c) 2013 Advanced Computing Technologies LLC
 .\ Written by: John H. Baldwin j...@freebsd.org
 .\ All rights reserved.
@@ -38,10 +38,10 @@
 .Sh SYNOPSIS
 .In stdio.h
 .Ft FILE *
-.Fn open_memstream char **bufp size_t **sizep
+.Fn open_memstream char **bufp size_t *sizep
 .In wchar.h
 .Ft FILE *
-.Fn open_wmemstream wchar_t **bufp size_t **sizep
+.Fn open_wmemstream wchar_t **bufp size_t *sizep
 .Sh DESCRIPTION
 The
 .Fn open_memstream



CVS commit: src/lib/libc/stdio

2014-10-13 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Oct 13 22:41:59 UTC 2014

Modified Files:
src/lib/libc/stdio: open_memstream.3

Log Message:
Fix whitespace in Xr. Remove sbuf(3) Xr, we do not have that.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdio/open_memstream.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/open_memstream.3
diff -u src/lib/libc/stdio/open_memstream.3:1.1 src/lib/libc/stdio/open_memstream.3:1.2
--- src/lib/libc/stdio/open_memstream.3:1.1	Mon Oct 13 00:40:36 2014
+++ src/lib/libc/stdio/open_memstream.3	Mon Oct 13 22:41:59 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: open_memstream.3,v 1.1 2014/10/13 00:40:36 christos Exp $
+.\	$NetBSD: open_memstream.3,v 1.2 2014/10/13 22:41:59 wiz Exp $
 .\ Copyright (c) 2013 Advanced Computing Technologies LLC
 .\ Written by: John H. Baldwin j...@freebsd.org
 .\ All rights reserved.
@@ -87,13 +87,13 @@ will contain the start of the memory buf
 will contain the smaller of the current position and the current buffer length.
 .Pp
 After a successful call to
-.Xr fflush 3,
+.Xr fflush 3 ,
 the pointer referenced by
 .Fa bufp
 and the variable referenced by
 .Fa sizep
 are only valid until the next write operation or a call to
-.Xr fclose 3.
+.Xr fclose 3 .
 .Pp
 Once a stream is closed,
 the allocated buffer referenced by
@@ -145,7 +145,6 @@ Memory for the stream or buffer could no
 .Xr fopen 3 ,
 .Xr free 3 ,
 .Xr fseek 3 ,
-.Xr sbuf 3 ,
 .Xr stdio 3
 .Sh STANDARDS
 The



CVS commit: src/lib/libc/stdio

2014-10-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 13 00:40:36 UTC 2014

Modified Files:
src/lib/libc/stdio: Makefile.inc
Added Files:
src/lib/libc/stdio: open_memstream.3 open_memstream.c open_wmemstream.c

Log Message:
PR/49279: Justin Cormack: add open_memstream


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/stdio/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/stdio/open_memstream.3 \
src/lib/libc/stdio/open_memstream.c src/lib/libc/stdio/open_wmemstream.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/Makefile.inc
diff -u src/lib/libc/stdio/Makefile.inc:1.45 src/lib/libc/stdio/Makefile.inc:1.46
--- src/lib/libc/stdio/Makefile.inc:1.45	Wed Jun 18 13:50:55 2014
+++ src/lib/libc/stdio/Makefile.inc	Sun Oct 12 20:40:36 2014
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	5.7 (Berkeley) 6/27/91
-#	$NetBSD: Makefile.inc,v 1.45 2014/06/18 17:50:55 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.46 2014/10/13 00:40:36 christos Exp $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
@@ -21,7 +21,7 @@ SRCS+=	clrerr.c dprintf.c fclose.c fdope
 	vasprintf.c vdprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c \
 	vprintf.c vscanf.c vsnprintf.c vsnprintf_ss.c vsscanf.c vswprintf.c \
 	vswscanf.c vwprintf.c vwscanf.c wbuf.c wprintf.c wscanf.c wsetup.c
-SRCS+=	fmemopen.c
+SRCS+=	fmemopen.c open_memstream.c open_wmemstream.c
 
 .if !defined(AUDIT)
 SRCS+=	gets.c vsprintf.c tempnam.c tmpnam.c mktemp.c
@@ -31,7 +31,7 @@ MAN+=	fclose.3 ferror.3 fflush.3 fgetln.
 	flockfile.3 fmemopen.3 fopen.3 fparseln.3 fputs.3 fputws.3 fread.3 \
 	fseek.3 funopen.3 fwide.3 getc.3 getdelim.3 getwc.3 mktemp.3 printf.3 \
 	putc.3 putwc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 \
-	ungetc.3 ungetwc.3 wprintf.3 wscanf.3
+	ungetc.3 ungetwc.3 wprintf.3 wscanf.3 open_memstream.3
 
 MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
 MLINKS+=fflush.3 fpurge.3
@@ -66,3 +66,4 @@ MLINKS+=wprintf.3 fwprintf.3 wprintf.3 s
 MLINKS+=wprintf.3 vwprintf.3 wprintf.3 vfwprintf.3 wprintf.3 vswprintf.3
 MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3
 MLINKS+=wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3
+MLINKS+=open_memstream.3 open_wmemstream.3

Added files:

Index: src/lib/libc/stdio/open_memstream.3
diff -u /dev/null src/lib/libc/stdio/open_memstream.3:1.1
--- /dev/null	Sun Oct 12 20:40:36 2014
+++ src/lib/libc/stdio/open_memstream.3	Sun Oct 12 20:40:36 2014
@@ -0,0 +1,156 @@
+.\	$NetBSD: open_memstream.3,v 1.1 2014/10/13 00:40:36 christos Exp $
+.\ Copyright (c) 2013 Advanced Computing Technologies LLC
+.\ Written by: John H. Baldwin j...@freebsd.org
+.\ All rights reserved.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in the
+.\documentation and/or other materials provided with the distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\ SUCH DAMAGE.
+.\
+.\ $FreeBSD: head/lib/libc/stdio/open_memstream.3 247415 2013-02-27 20:09:25Z joel $
+.\
+.Dd October 12, 2014
+.Dt OPEN_MEMSTREAM 3
+.Os
+.Sh NAME
+.Nm open_memstream ,
+.Nm open_wmemstream
+.Nd dynamic memory buffer stream open functions
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft FILE *
+.Fn open_memstream char **bufp size_t **sizep
+.In wchar.h
+.Ft FILE *
+.Fn open_wmemstream wchar_t **bufp size_t **sizep
+.Sh DESCRIPTION
+The
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions create a write-only, seekable stream backed by a dynamically
+allocated memory buffer.
+The
+.Fn open_memstream
+function creates a byte-oriented stream,
+while the
+.Fn open_wmemstream
+function creates a wide-oriented stream.
+.Pp
+Each stream maintains a current position and size.
+Initially,
+the position and size are set to zero.
+Each write begins at the current position and advances it the number of

CVS commit: src/lib/libc/stdio

2014-09-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 29 14:58:33 UTC 2014

Modified Files:
src/lib/libc/stdio: printf.3 vsnprintf.c vsnprintf_ss.c

Log Message:
Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX
(well FreeBSD documents INT_MAX + 1, but in the code it is INT_MAX).


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libc/stdio/printf.3
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdio/vsnprintf.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/vsnprintf_ss.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/printf.3
diff -u src/lib/libc/stdio/printf.3:1.63 src/lib/libc/stdio/printf.3:1.64
--- src/lib/libc/stdio/printf.3:1.63	Sat May  4 15:17:38 2013
+++ src/lib/libc/stdio/printf.3	Mon Sep 29 10:58:33 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: printf.3,v 1.63 2013/05/04 19:17:38 wiz Exp $
+.\	$NetBSD: printf.3,v 1.64 2014/09/29 14:58:33 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 May 4, 2013
+.Dd September 29, 2014
 .Dt PRINTF 3
 .Os
 .Sh NAME
@@ -799,6 +799,13 @@ family of functions may fail if:
 An invalid wide-character code was encountered.
 .It Bq Er ENOMEM
 Insufficient storage space is available.
+.It Bq Er EOVERFLOW
+The
+.Fa size
+argument exceeds
+.Dv INT_MAX ,
+or the return value would be too large to be represented by an
+.Vt int .
 .El
 .Sh SEE ALSO
 .Xr printf 1 ,

Index: src/lib/libc/stdio/vsnprintf.c
diff -u src/lib/libc/stdio/vsnprintf.c:1.27 src/lib/libc/stdio/vsnprintf.c:1.28
--- src/lib/libc/stdio/vsnprintf.c:1.27	Fri May 17 08:55:57 2013
+++ src/lib/libc/stdio/vsnprintf.c	Mon Sep 29 10:58:33 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsnprintf.c,v 1.27 2013/05/17 12:55:57 joerg Exp $	*/
+/*	$NetBSD: vsnprintf.c,v 1.28 2014/09/29 14:58:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)vsnprintf.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: vsnprintf.c,v 1.27 2013/05/17 12:55:57 joerg Exp $);
+__RCSID($NetBSD: vsnprintf.c,v 1.28 2014/09/29 14:58:33 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -76,8 +76,8 @@ vsnprintf_l(char *str, size_t n, locale_
 	_DIAGASSERT(n == 0 || str != NULL);
 	_DIAGASSERT(fmt != NULL);
 
-	if ((int)n  0) {
-		errno = EINVAL;
+	if (n  INT_MAX) {
+		errno = EOVERFLOW;
 		return -1;
 	}
 

Index: src/lib/libc/stdio/vsnprintf_ss.c
diff -u src/lib/libc/stdio/vsnprintf_ss.c:1.12 src/lib/libc/stdio/vsnprintf_ss.c:1.13
--- src/lib/libc/stdio/vsnprintf_ss.c:1.12	Thu Mar 15 14:22:31 2012
+++ src/lib/libc/stdio/vsnprintf_ss.c	Mon Sep 29 10:58:33 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsnprintf_ss.c,v 1.12 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: vsnprintf_ss.c,v 1.13 2014/09/29 14:58:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)vsnprintf.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: vsnprintf_ss.c,v 1.12 2012/03/15 18:22:31 christos Exp $);
+__RCSID($NetBSD: vsnprintf_ss.c,v 1.13 2014/09/29 14:58:33 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -144,8 +144,8 @@ vsnprintf_ss(char *sbuf, size_t slen, co
 	_DIAGASSERT(slen == 0 || sbuf != NULL);
 	_DIAGASSERT(fmt0 != NULL);
 
-	if ((int)slen  0) {
-		errno = EINVAL;
+	if (slen  INT_MAX) {
+		errno = EOVERFLOW;
 		return -1;
 	}
 



CVS commit: src/lib/libc/stdio

2014-09-16 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Tue Sep 16 08:42:20 UTC 2014

Modified Files:
src/lib/libc/stdio: getdelim.3

Log Message:
Rephrase the NOTE about embedded NUL characters, using apparent length
for what strlen(3) reports, and true length for what the return value
reports.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/getdelim.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/getdelim.3
diff -u src/lib/libc/stdio/getdelim.3:1.12 src/lib/libc/stdio/getdelim.3:1.13
--- src/lib/libc/stdio/getdelim.3:1.12	Mon Sep 15 23:41:16 2014
+++ src/lib/libc/stdio/getdelim.3	Tue Sep 16 08:42:20 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: getdelim.3,v 1.12 2014/09/15 23:41:16 christos Exp $
+.\ $NetBSD: getdelim.3,v 1.13 2014/09/16 08:42:20 apb Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -161,9 +161,9 @@ The
 .Fn getdelim
 and
 .Fn getline
-functions can return strings with length (as returned by
-.Xr strlen 3
-on the returned line) less than the return value of the functions
-if the line happened to contain
+functions can return results that include
 .Dv NUL
-characters.
+characters, which can cause the apparent length reported by
+.Xr strlen 3
+to be less than the true length reported by the
+return values of the functions.



CVS commit: src/lib/libc/stdio

2014-09-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Sep 16 08:52:02 UTC 2014

Modified Files:
src/lib/libc/stdio: getdelim.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/getdelim.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/getdelim.3
diff -u src/lib/libc/stdio/getdelim.3:1.13 src/lib/libc/stdio/getdelim.3:1.14
--- src/lib/libc/stdio/getdelim.3:1.13	Tue Sep 16 08:42:20 2014
+++ src/lib/libc/stdio/getdelim.3	Tue Sep 16 08:52:02 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: getdelim.3,v 1.13 2014/09/16 08:42:20 apb Exp $
+.\ $NetBSD: getdelim.3,v 1.14 2014/09/16 08:52:02 wiz Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -48,7 +48,7 @@ The
 function reads from the
 .Fa stream
 until it encounters a character matching
-.Fa delimiter 
+.Fa delimiter
 or
 .Dv EOF ,
 storing the input in



CVS commit: src/lib/libc/stdio

2014-09-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 15 23:29:16 UTC 2014

Modified Files:
src/lib/libc/stdio: getdelim.3

Log Message:
Fix documentation to reflect what happens when EOF is found before delimiter,
aligning us with POSIX.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdio/getdelim.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/getdelim.3
diff -u src/lib/libc/stdio/getdelim.3:1.9 src/lib/libc/stdio/getdelim.3:1.10
--- src/lib/libc/stdio/getdelim.3:1.9	Wed Apr 20 19:37:51 2011
+++ src/lib/libc/stdio/getdelim.3	Mon Sep 15 19:29:16 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: getdelim.3,v 1.9 2011/04/20 23:37:51 enami Exp $
+.\ $NetBSD: getdelim.3,v 1.10 2014/09/15 23:29:16 christos Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd June 30, 2010
+.Dd September 15, 2014
 .Dt GETDELIM 3
 .Os
 .Sh NAME
@@ -48,12 +48,14 @@ The
 function reads from the
 .Fa stream
 until it encounters a character matching
-.Fa delimiter ,
+.Fa delimiter 
+or.
+.DV EOF ,
 storing the input in
 .Fa *lineptr .
 The buffer is
 .Dv NUL Ns No -terminated
-and includes the delimiter.
+and includes the delimiter, if one was found.
 The
 .Fa delimiter
 character must be representable as an unsigned char.
@@ -88,7 +90,8 @@ The
 .Fn getdelim
 and
 .Fn getline
-functions return the number of characters read, including the delimiter.
+functions return the number of characters read, including the delimiter if
+one was found.
 If no characters were read and the stream is at end-of-file, the functions
 return \-1.
 If an error occurs, the functions return \-1 and the global variable



CVS commit: src/lib/libc/stdio

2014-09-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 15 23:31:17 UTC 2014

Modified Files:
src/lib/libc/stdio: getdelim.3

Log Message:
fix markup.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdio/getdelim.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/getdelim.3
diff -u src/lib/libc/stdio/getdelim.3:1.10 src/lib/libc/stdio/getdelim.3:1.11
--- src/lib/libc/stdio/getdelim.3:1.10	Mon Sep 15 19:29:16 2014
+++ src/lib/libc/stdio/getdelim.3	Mon Sep 15 19:31:17 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: getdelim.3,v 1.10 2014/09/15 23:29:16 christos Exp $
+.\ $NetBSD: getdelim.3,v 1.11 2014/09/15 23:31:17 christos Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -49,8 +49,8 @@ function reads from the
 .Fa stream
 until it encounters a character matching
 .Fa delimiter 
-or.
-.DV EOF ,
+or
+.Dv EOF ,
 storing the input in
 .Fa *lineptr .
 The buffer is



CVS commit: src/lib/libc/stdio

2014-09-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 15 23:41:16 UTC 2014

Modified Files:
src/lib/libc/stdio: getdelim.3

Log Message:
mention what happens if the line contains NUL's.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdio/getdelim.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/getdelim.3
diff -u src/lib/libc/stdio/getdelim.3:1.11 src/lib/libc/stdio/getdelim.3:1.12
--- src/lib/libc/stdio/getdelim.3:1.11	Mon Sep 15 19:31:17 2014
+++ src/lib/libc/stdio/getdelim.3	Mon Sep 15 19:41:16 2014
@@ -1,4 +1,4 @@
-.\ $NetBSD: getdelim.3,v 1.11 2014/09/15 23:31:17 christos Exp $
+.\ $NetBSD: getdelim.3,v 1.12 2014/09/15 23:41:16 christos Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -147,7 +147,8 @@ or
 .Sh SEE ALSO
 .Xr ferror 3 ,
 .Xr fgets 3 ,
-.Xr fopen 3
+.Xr fopen 3 ,
+.Xr strlen 3
 .Sh STANDARDS
 The
 .Fn getdelim
@@ -155,3 +156,14 @@ and
 .Fn getline
 functions conform to
 .St -p1003.1-2008 .
+.Sh NOTES
+The
+.Fn getdelim
+and
+.Fn getline
+functions can return strings with length (as returned by
+.Xr strlen 3
+on the returned line) less than the return value of the functions
+if the line happened to contain
+.Dv NUL
+characters.



CVS commit: src/lib/libc/stdio

2014-06-19 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Jun 19 09:30:33 UTC 2014

Modified Files:
src/lib/libc/stdio: mktemp.3

Log Message:
Add all functions to NAME section. End sentences with dots.
Bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/lib/libc/stdio/mktemp.3:1.30
--- src/lib/libc/stdio/mktemp.3:1.29	Wed Jun 18 17:47:58 2014
+++ src/lib/libc/stdio/mktemp.3	Thu Jun 19 09:30:33 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: mktemp.3,v 1.29 2014/06/18 17:47:58 christos Exp $
+.\	$NetBSD: mktemp.3,v 1.30 2014/06/19 09:30:33 wiz Exp $
 .\
 .\ Copyright (c) 1989, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -29,12 +29,15 @@
 .\
 .\ @(#)mktemp.3	8.1 (Berkeley) 6/4/93
 .\
-.Dd April 29, 2010
+.Dd June 18, 2014
 .Dt MKTEMP 3
 .Os
 .Sh NAME
 .Nm mktemp ,
 .Nm mkstemp ,
+.Nm mkstemps ,
+.Nm mkostemp ,
+.Nm mkostemps ,
 .Nm mkdtemp
 .Nd make unique temporary file or directory name
 .Sh LIBRARY
@@ -335,17 +338,17 @@ The
 function first appeared in
 .Ox 2.4 ,
 and later in
-.Fx 3.4 
+.Fx 3.4
 and
-.Nx 7.0
+.Nx 7.0 .
 The
 .Fn mkostemp
 and
 .Fn mkostemps
 functions appeared in
-.Fx 10.0 
+.Fx 10.0
 and
-.Nx 7.0
+.Nx 7.0 .
 .Sh BUGS
 For
 .Fn mktemp



CVS commit: src/lib/libc/stdio

2014-06-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 19 14:27:50 UTC 2014

Modified Files:
src/lib/libc/stdio: fgetln.3

Log Message:
Fix incorrect example (what happens when len == 0?)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 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.14 src/lib/libc/stdio/fgetln.3:1.15
--- src/lib/libc/stdio/fgetln.3:1.14	Mon May 10 13:15:28 2004
+++ src/lib/libc/stdio/fgetln.3	Thu Jun 19 10:27:50 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: fgetln.3,v 1.14 2004/05/10 17:15:28 drochner Exp $
+.\	$NetBSD: fgetln.3,v 1.15 2014/06/19 14:27:50 christos 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 April 21, 2004
+.Dd June 19, 2014
 .Dt FGETLN 3
 .Os
 .Sh NAME
@@ -134,22 +134,14 @@ temporary buffer:
 	char *buf, *lbuf;
 	size_t len;
 
-	lbuf = NULL;
-	while ((buf = fgetln(fp, len))) {
-		if (buf[len - 1] == '\en')
+	while ((lbuf = buf = fgetln(fp, len)) != NULL) {
+		if (len  0  buf[len - 1] == '\en')
 			buf[len - 1] = '\e0';
-		else {
-			if ((lbuf = (char *)malloc(len + 1)) == NULL)
+		else if ((lbuf = strndup(buf, len + 1)) == NULL)
 err(1, NULL);
-			memcpy(lbuf, buf, len);
-			lbuf[len] = '\e0';
-			buf = lbuf;
-		}
-		printf(%s\en, buf);
+		printf(%s\en, lbuf);
 
-		if (lbuf != NULL) {
+		if (lbuf != buf)
 			free(lbuf);
-			lbuf = NULL;
-		}
 	}
 .Ed



CVS commit: src/lib/libc/stdio

2014-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun 18 17:50:55 UTC 2014

Modified Files:
src/lib/libc/stdio: Makefile.inc

Log Message:
more man pages links


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/lib/libc/stdio/Makefile.inc

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/Makefile.inc
diff -u src/lib/libc/stdio/Makefile.inc:1.44 src/lib/libc/stdio/Makefile.inc:1.45
--- src/lib/libc/stdio/Makefile.inc:1.44	Wed Jun 18 13:47:58 2014
+++ src/lib/libc/stdio/Makefile.inc	Wed Jun 18 13:50:55 2014
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	5.7 (Berkeley) 6/27/91
-#	$NetBSD: Makefile.inc,v 1.44 2014/06/18 17:47:58 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.45 2014/06/18 17:50:55 christos Exp $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
@@ -48,6 +48,8 @@ MLINKS+=getc.3 fgetc.3 getc.3 getc_unloc
 	getc.3 getchar_unlocked.3 getc.3 getw.3
 MLINKS+=getdelim.3 getline.3
 MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3
+MLINKS+=mktemp.3 mkostemp.3 mktemp.3 mkostemps.3
+MLINKS+=mktemp.3 mkstemps.3
 MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 printf.3 snprintf.3 \
 	printf.3 sprintf.3 printf.3 vasprintf.3 printf.3 vfprintf.3 \
 	printf.3 vprintf.3 printf.3 vsnprintf.3 printf.3 vsprintf.3 \



CVS commit: src/lib/libc/stdio

2014-06-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 19 05:31:15 UTC 2014

Modified Files:
src/lib/libc/stdio: gettemp.c

Log Message:
Fix shadows a global declaration compile error.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/gettemp.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/gettemp.c
diff -u src/lib/libc/stdio/gettemp.c:1.18 src/lib/libc/stdio/gettemp.c:1.19
--- src/lib/libc/stdio/gettemp.c:1.18	Wed Jun 18 17:47:58 2014
+++ src/lib/libc/stdio/gettemp.c	Thu Jun 19 05:31:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gettemp.c,v 1.18 2014/06/18 17:47:58 christos Exp $	*/
+/*	$NetBSD: gettemp.c,v 1.19 2014/06/19 05:31:15 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = @(#)mktemp.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: gettemp.c,v 1.18 2014/06/18 17:47:58 christos Exp $);
+__RCSID($NetBSD: gettemp.c,v 1.19 2014/06/19 05:31:15 msaitoh Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -56,7 +56,7 @@ GETTEMP(char *path, int *doopen, int dom
 	char *pad;
 	struct stat sbuf;
 	int rval;
-	uint32_t rand;
+	uint32_t r;
 	char carrybuf[MAXPATHLEN];
 
 	_DIAGASSERT(path != NULL);
@@ -85,8 +85,8 @@ GETTEMP(char *path, int *doopen, int dom
 
 	/* Fill space with random characters */
 	while (trv = path  *trv == 'X') {
-		rand = arc4random_uniform(sizeof(padchar) - 1);
-		*trv-- = padchar[rand];
+		r = arc4random_uniform(sizeof(padchar) - 1);
+		*trv-- = padchar[r];
 	}
 	start = trv + 1;
 



CVS commit: src/lib/libc/stdio

2014-06-12 Thread Justin Cormack
Module Name:src
Committed By:   justin
Date:   Thu Jun 12 22:21:20 UTC 2014

Modified Files:
src/lib/libc/stdio: vfwscanf.c

Log Message:
gcc cannot always work out initialization here


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdio/vfwscanf.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/vfwscanf.c
diff -u src/lib/libc/stdio/vfwscanf.c:1.11 src/lib/libc/stdio/vfwscanf.c:1.12
--- src/lib/libc/stdio/vfwscanf.c:1.11	Mon Sep 23 12:41:37 2013
+++ src/lib/libc/stdio/vfwscanf.c	Thu Jun 12 22:21:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $	*/
+/*	$NetBSD: vfwscanf.c,v 1.12 2014/06/12 22:21:20 justin Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@
 static char sccsid[] = @(#)ftell.c	8.2 (Berkeley) 5/4/95;
 __FBSDID($FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $);
 #else
-__RCSID($NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $);
+__RCSID($NetBSD: vfwscanf.c,v 1.12 2014/06/12 22:21:20 justin Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -180,6 +180,7 @@ __vfwscanf_unlocked_l(FILE * __restrict 
 	base = 0;
 	cclcompl = 0;
 	mbp = NULL;
+	p = NULL; /* XXXgcc */
 	for (;;) {
 		c = *fmt++;
 		if (c == 0)



CVS commit: src/lib/libc/stdio

2014-01-21 Thread Sean Boudreau
Module Name:src
Committed By:   seanb
Date:   Tue Jan 21 19:09:48 UTC 2014

Modified Files:
src/lib/libc/stdio: gettemp.c

Log Message:
Handle case where a 0 length template string or a template
of all 'X' would dereference, and maybe assign to, memory
before the template.  Simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/gettemp.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/gettemp.c
diff -u src/lib/libc/stdio/gettemp.c:1.16 src/lib/libc/stdio/gettemp.c:1.17
--- src/lib/libc/stdio/gettemp.c:1.16	Mon Apr 22 20:57:36 2013
+++ src/lib/libc/stdio/gettemp.c	Tue Jan 21 19:09:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $	*/
+/*	$NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = @(#)mktemp.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $);
+__RCSID($NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -89,14 +89,18 @@ GETTEMP(char *path, int *doopen, int dom
 			xcnt = 0;	
 
 	/* Use at least one from xtra.  Use 2 if more than 6 X's. */
-	if (*(trv - 1) == 'X')
+	if (xcnt  0) {
 		*--trv = xtra[0];
-	if (xcnt  6  *(trv - 1) == 'X')
+		xcnt--;
+	}
+	if (xcnt  5) {
 		*--trv = xtra[1];
+		xcnt--;
+	}
 
 	/* Set remaining X's to pid digits with 0's to the left. */
-	while (*--trv == 'X') {
-		*trv = (pid % 10) + '0';
+	for (; xcnt  0; xcnt--) {
+		*--trv = (pid % 10) + '0';
 		pid /= 10;
 	}
 



CVS commit: src/lib/libc/stdio

2014-01-20 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Mon Jan 20 14:11:03 UTC 2014

Modified Files:
src/lib/libc/stdio: vfwprintf.c

Log Message:
vfwprintf: fix error propagation
PR/47660 (Julio Merino)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 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.33 src/lib/libc/stdio/vfwprintf.c:1.34
--- src/lib/libc/stdio/vfwprintf.c:1.33	Mon Sep 23 12:41:37 2013
+++ src/lib/libc/stdio/vfwprintf.c	Mon Jan 20 14:11:03 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.33 2013/09/23 12:41:37 pooka Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt 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.33 2013/09/23 12:41:37 pooka Exp $);
+__RCSID($NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -712,7 +712,10 @@ WDECL(__vf,printf_unlocked_l)(FILE *fp, 
 #ifndef NARROW
 #define	PRINT(ptr, len)	do {			\
 	for (n3 = 0; n3  (len); n3++)		\
-		__xfputwc((ptr)[n3], fp, loc);	\
+		if (__xfputwc((ptr)[n3], fp, loc) == END_OF_FILE) { \
+			fp-_flags |= __SERR;	\
+			goto error;		\
+		}\
 } while (/*CONSTCOND*/0)
 #define FLUSH()
 #else



CVS commit: src/lib/libc/stdio

2014-01-07 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Tue Jan  7 13:34:11 UTC 2014

Modified Files:
src/lib/libc/stdio: fparseln.3

Log Message:
Kill unneeded paragraph macro.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdio/fparseln.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/fparseln.3
diff -u src/lib/libc/stdio/fparseln.3:1.4 src/lib/libc/stdio/fparseln.3:1.5
--- src/lib/libc/stdio/fparseln.3:1.4	Wed Oct 21 01:07:45 2009
+++ src/lib/libc/stdio/fparseln.3	Tue Jan  7 13:34:11 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: fparseln.3,v 1.4 2009/10/21 01:07:45 snj Exp $
+.\	$NetBSD: fparseln.3,v 1.5 2014/01/07 13:34:11 njoly Exp $
 .\
 .\ Copyright (c) 1997 Christos Zoulas.  All rights reserved.
 .\
@@ -114,7 +114,6 @@ Remove escape preceding any other charac
 .It Dv FPARSELN_UNESCALL
 All of the above.
 .El
-.Pp
 .El
 .Sh RETURN VALUES
 Upon successful completion a pointer to the parsed line is returned;



CVS commit: src/lib/libc/stdio

2013-09-23 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Sep 23 12:41:37 UTC 2013

Modified Files:
src/lib/libc/stdio: vfwprintf.c vfwscanf.c

Log Message:
Make compile with -DNO_FLOATING_POINT


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/vfwprintf.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdio/vfwscanf.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.32 src/lib/libc/stdio/vfwprintf.c:1.33
--- src/lib/libc/stdio/vfwprintf.c:1.32	Fri May 17 12:55:57 2013
+++ src/lib/libc/stdio/vfwprintf.c	Mon Sep 23 12:41:37 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.32 2013/05/17 12:55:57 joerg Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.33 2013/09/23 12:41:37 pooka 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.32 2013/05/17 12:55:57 joerg Exp $);
+__RCSID($NetBSD: vfwprintf.c,v 1.33 2013/09/23 12:41:37 pooka Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -821,13 +821,12 @@ WDECL(__vf,printf_unlocked_l)(FILE *fp, 
 
 	_SET_ORIENTATION(fp, -1);
 
-	ndig = -1;	/* XXX gcc */
-
 	thousands_sep = '\0';
 	grouping = NULL;
 #ifndef NO_FLOATING_POINT
 	decimal_point = localeconv_l(loc)-decimal_point;
 	expsize = 0;		/* XXXGCC -Wuninitialized [sh3,m68000] */
+	ndig = -1;	/* XXX gcc */
 #endif
 	convbuf = NULL;
 	/* sorry, f{w,}printf(read_only_file, L) returns {W,}EOF, not 0 */
@@ -879,9 +878,11 @@ WDECL(__vf,printf_unlocked_l)(FILE *fp, 
 		prec = -1;
 		sign = '\0';
 		ox[1] = '\0';
+#ifndef NO_FLOATING_POINT
 		expchar = '\0';
 		lead = 0;
 		nseps = nrepeats = 0;
+#endif
 		ulval = 0;
 		ujval = 0;
 		xdigs = NULL;

Index: src/lib/libc/stdio/vfwscanf.c
diff -u src/lib/libc/stdio/vfwscanf.c:1.10 src/lib/libc/stdio/vfwscanf.c:1.11
--- src/lib/libc/stdio/vfwscanf.c:1.10	Fri May 17 12:55:57 2013
+++ src/lib/libc/stdio/vfwscanf.c	Mon Sep 23 12:41:37 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwscanf.c,v 1.10 2013/05/17 12:55:57 joerg Exp $	*/
+/*	$NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@
 static char sccsid[] = @(#)ftell.c	8.2 (Berkeley) 5/4/95;
 __FBSDID($FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $);
 #else
-__RCSID($NetBSD: vfwscanf.c,v 1.10 2013/05/17 12:55:57 joerg Exp $);
+__RCSID($NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -102,7 +102,9 @@ __RCSID($NetBSD: vfwscanf.c,v 1.10 2013
 #define	CT_INT		3	/* %[dioupxX] conversion */
 #define	CT_FLOAT	4	/* %[efgEFG] conversion */
 
+#ifndef NO_FLOATING_POINT
 static int parsefloat(FILE *, wchar_t *, wchar_t *, locale_t);
+#endif
 
 #define	INCCL(_c)	\
 	(cclcompl ? (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) == NULL) : \



CVS commit: src/lib/libc/stdio

2013-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May 19 17:07:05 UTC 2013

Modified Files:
src/lib/libc/stdio: stdio.c

Log Message:
from kre: Don't fail if we are seeking on a pipe, clear the append bit
since we always append.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/stdio/stdio.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/stdio.c
diff -u src/lib/libc/stdio/stdio.c:1.21 src/lib/libc/stdio/stdio.c:1.22
--- src/lib/libc/stdio/stdio.c:1.21	Tue Mar 27 11:05:42 2012
+++ src/lib/libc/stdio/stdio.c	Sun May 19 13:07:04 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $	*/
+/*	$NetBSD: stdio.c,v 1.22 2013/05/19 17:07:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)stdio.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $);
+__RCSID($NetBSD: stdio.c,v 1.22 2013/05/19 17:07:04 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -86,8 +86,12 @@ __swrite(void *cookie, const void *buf, 
 	_DIAGASSERT(buf != NULL);
 
 	if (fp-_flags  __SAPP)
-		if (lseek(__sfileno(fp), (off_t)0, SEEK_END) == (off_t)-1)
-			return -1;
+		if (lseek(__sfileno(fp), (off_t)0, SEEK_END) == (off_t)-1) {
+			if (errno == ESPIPE)/* if unseekable, OK, */
+fp-_flags = ~__SAPP;  /* all writes append. */
+			else
+return -1;
+		}
 	fp-_flags = ~__SOFF;	/* in case FAPPEND mode is set */
 	return write(__sfileno(fp), buf, n);
 }



CVS commit: src/lib/libc/stdio

2013-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May 19 21:45:00 UTC 2013

Modified Files:
src/lib/libc/stdio: vasprintf.c vswprintf.c

Log Message:
don't cast malloc


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/vasprintf.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdio/vswprintf.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/vasprintf.c
diff -u src/lib/libc/stdio/vasprintf.c:1.16 src/lib/libc/stdio/vasprintf.c:1.17
--- src/lib/libc/stdio/vasprintf.c:1.16	Fri May 17 08:55:57 2013
+++ src/lib/libc/stdio/vasprintf.c	Sun May 19 17:45:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vasprintf.c,v 1.16 2013/05/17 12:55:57 joerg Exp $	*/
+/*	$NetBSD: vasprintf.c,v 1.17 2013/05/19 21:45:00 christos Exp $	*/
 
 /*
  * Copyright (c) 1997 Todd C. Miller todd.mil...@courtesan.com
@@ -29,7 +29,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: vasprintf.c,v 1.16 2013/05/17 12:55:57 joerg Exp $);
+__RCSID($NetBSD: vasprintf.c,v 1.17 2013/05/19 21:45:00 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -63,7 +63,7 @@ vasprintf_l(char **str, locale_t loc, co
 	_FILEEXT_SETUP(f, fext);
 	f._file = -1;
 	f._flags = __SWR | __SSTR | __SALC;
-	f._bf._base = f._p = (unsigned char *)malloc(128);
+	f._bf._base = f._p = malloc(128);
 	if (f._bf._base == NULL)
 		goto err;
 	f._bf._size = f._w = 127;		/* Leave room for the NUL */

Index: src/lib/libc/stdio/vswprintf.c
diff -u src/lib/libc/stdio/vswprintf.c:1.5 src/lib/libc/stdio/vswprintf.c:1.6
--- src/lib/libc/stdio/vswprintf.c:1.5	Fri May 17 08:55:57 2013
+++ src/lib/libc/stdio/vswprintf.c	Sun May 19 17:45:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vswprintf.c,v 1.5 2013/05/17 12:55:57 joerg Exp $	*/
+/*	$NetBSD: vswprintf.c,v 1.6 2013/05/19 21:45:00 christos Exp $	*/
 
 /*
  * Copyright (c) 1997 Todd C. Miller todd.mil...@courtesan.com
@@ -32,7 +32,7 @@
 #if 0
 __FBSDID($FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.6 2005/02/21 19:41:44 fjoe Exp $);
 #else
-__RCSID($NetBSD: vswprintf.c,v 1.5 2013/05/17 12:55:57 joerg Exp $);
+__RCSID($NetBSD: vswprintf.c,v 1.6 2013/05/19 21:45:00 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -70,7 +70,7 @@ vswprintf_l(wchar_t * __restrict s, size
 	_FILEEXT_SETUP(f, fext);
 	f._file = -1;
 	f._flags = __SWR | __SSTR | __SALC;
-	f._bf._base = f._p = (unsigned char *)malloc(128);
+	f._bf._base = f._p = malloc(128);
 	if (f._bf._base == NULL) {
 		errno = ENOMEM;
 		return -1;



CVS commit: src/lib/libc/stdio

2013-05-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat May  4 18:35:54 UTC 2013

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
_ss improvements


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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.61 src/lib/libc/stdio/printf.3:1.62
--- src/lib/libc/stdio/printf.3:1.61	Sun Jan 20 06:01:17 2013
+++ src/lib/libc/stdio/printf.3	Sat May  4 14:35:53 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: printf.3,v 1.61 2013/01/20 11:01:17 uwe Exp $
+.\	$NetBSD: printf.3,v 1.62 2013/05/04 18:35: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 December 26, 2010
+.Dd May 4, 2013
 .Dt PRINTF 3
 .Os
 .Sh NAME
@@ -42,6 +42,7 @@
 .Nm dprintf
 .Nm sprintf ,
 .Nm snprintf ,
+.Nm snprintf_ss ,
 .Nm asprintf ,
 .Nm vprintf ,
 .Nm vfprintf ,
@@ -66,6 +67,8 @@
 .Ft int
 .Fn snprintf char * restrict str size_t size const char * restrict format ...
 .Ft int
+.Fn snprintf_ss char * restrict str size_t size const char * restrict format ...
+.Ft int
 .Fn asprintf char ** restrict ret const char * restrict format ...
 .In stdarg.h
 .Ft int
@@ -108,6 +111,7 @@ write output to the given file descripto
 .Fa fd ;
 .Fn sprintf ,
 .Fn snprintf ,
+.Fn snprintf_ss ,
 .Fn vsprintf ,
 .Fn vsnprintf ,
 and
@@ -128,9 +132,11 @@ string that specifies how subsequent arg
 .Xr stdarg 3 )
 are converted for output.
 .Pp
+.Fn snprintf_ss
+and
 .Fn vsnprintf_ss
-is a signal-safe standalone version that does not handle
-floating point formats.
+are signal-safe standalone versions that does not handle
+floating point formats, positional arguments, and wide characters.
 .Pp
 .Fn asprintf
 and



CVS commit: src/lib/libc/stdio

2013-05-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat May  4 19:17:39 UTC 2013

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
Grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/lib/libc/stdio/printf.3:1.63
--- src/lib/libc/stdio/printf.3:1.62	Sat May  4 18:35:53 2013
+++ src/lib/libc/stdio/printf.3	Sat May  4 19:17:38 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: printf.3,v 1.62 2013/05/04 18:35:53 christos Exp $
+.\	$NetBSD: printf.3,v 1.63 2013/05/04 19:17:38 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -135,7 +135,7 @@ are converted for output.
 .Fn snprintf_ss
 and
 .Fn vsnprintf_ss
-are signal-safe standalone versions that does not handle
+are signal-safe standalone versions that do not handle
 floating point formats, positional arguments, and wide characters.
 .Pp
 .Fn asprintf



CVS commit: src/lib/libc/stdio

2013-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Apr 22 19:33:54 UTC 2013

Modified Files:
src/lib/libc/stdio: vswscanf.c

Log Message:
Add new line at the end.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdio/vswscanf.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/vswscanf.c
diff -u src/lib/libc/stdio/vswscanf.c:1.10 src/lib/libc/stdio/vswscanf.c:1.11
--- src/lib/libc/stdio/vswscanf.c:1.10	Fri Apr 19 23:32:17 2013
+++ src/lib/libc/stdio/vswscanf.c	Mon Apr 22 19:33:53 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vswscanf.c,v 1.10 2013/04/19 23:32:17 joerg Exp $	*/
+/*	$NetBSD: vswscanf.c,v 1.11 2013/04/22 19:33:53 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@
 static char sccsid[] = @(#)vsscanf.c	8.1 (Berkeley) 6/4/93;
 __FBSDID($FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $);
 #else
-__RCSID($NetBSD: vswscanf.c,v 1.10 2013/04/19 23:32:17 joerg Exp $);
+__RCSID($NetBSD: vswscanf.c,v 1.11 2013/04/22 19:33:53 joerg Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -116,4 +116,4 @@ vswscanf(const wchar_t * __restrict str,
 va_list ap)
 {
 	return vswscanf_l(str, *_current_locale(), fmt, ap);
-}
\ No newline at end of file
+}



CVS commit: src/lib/libc/stdio

2013-04-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 22 20:57:36 UTC 2013

Modified Files:
src/lib/libc/stdio: gettemp.c

Log Message:
PR/47757: Eric Radman: mktemp(3) mangles the pathname if not given an absolute
path
1. on error, gettemp() did not restore the path string
2. when emulating mktemp() it is not an error for the pattern not to represent
   a real directory structure
XXX[1]: pullup-5, pullup-6
XXX[2]: the default pattern is the simplistic pidX for mktemp.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/gettemp.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/gettemp.c
diff -u src/lib/libc/stdio/gettemp.c:1.15 src/lib/libc/stdio/gettemp.c:1.16
--- src/lib/libc/stdio/gettemp.c:1.15	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/gettemp.c	Mon Apr 22 16:57:36 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = @(#)mktemp.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -119,14 +119,16 @@ GETTEMP(char *path, int *doopen, int dom
 		if (trv = path)
 			break;
 		if (*trv == '/') {
+			int e;
 			*trv = '\0';
-			if (stat(path, sbuf))
-return 0;
+			e = stat(path, sbuf);
+			*trv = '/';
+			if (e == -1)
+return doopen == NULL  !domkdir;
 			if (!S_ISDIR(sbuf.st_mode)) {
 errno = ENOTDIR;
-return 0;
+return doopen == NULL  !domkdir;
 			}
-			*trv = '/';
 			break;
 		}
 	}



CVS commit: src/lib/libc/stdio

2013-01-20 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sun Jan 20 10:57:19 UTC 2013

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
In newfmt() example one level of indentation is enough.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/lib/libc/stdio/printf.3:1.60
--- src/lib/libc/stdio/printf.3:1.59	Sat Jan 19 15:25:58 2013
+++ src/lib/libc/stdio/printf.3	Sun Jan 20 10:57:19 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: printf.3,v 1.59 2013/01/19 15:25:58 uwe Exp $
+.\	$NetBSD: printf.3,v 1.60 2013/01/20 10:57:19 uwe Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -772,14 +772,14 @@ To allocate a 128 byte string and print 
 #include \*[Lt]stdarg.h\*[Gt]
 char *newfmt(const char *fmt, ...)
 {
-		char *p;
-		va_list ap;
-		if ((p = malloc(128)) == NULL)
-			return (NULL);
-		va_start(ap, fmt);
-		(void) vsnprintf(p, 128, fmt, ap);
-		va_end(ap);
-		return (p);
+	char *p;
+	va_list ap;
+	if ((p = malloc(128)) == NULL)
+		return (NULL);
+	va_start(ap, fmt);
+	(void) vsnprintf(p, 128, fmt, ap);
+	va_end(ap);
+	return (p);
 }
 .Ed
 .Sh ERRORS



CVS commit: src/lib/libc/stdio

2013-01-20 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sun Jan 20 11:01:17 UTC 2013

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
Mark up occurence of printf() in text with .Fn


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 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.60 src/lib/libc/stdio/printf.3:1.61
--- src/lib/libc/stdio/printf.3:1.60	Sun Jan 20 10:57:19 2013
+++ src/lib/libc/stdio/printf.3	Sun Jan 20 11:01:17 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: printf.3,v 1.60 2013/01/20 10:57:19 uwe Exp $
+.\	$NetBSD: printf.3,v 1.61 2013/01/20 11:01:17 uwe Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -884,7 +884,9 @@ Be sure to use the proper secure idiom:
 snprintf(buffer, sizeof(buffer), %s, string);
 .Ed
 .Pp
-There is no way for printf to know the size of each argument passed.
+There is no way for
+.Fn printf
+to know the size of each argument passed.
 If you use positional arguments you must ensure that all parameters, up to the
 last positionally specified parameter, are used in the format string.
 This allows for the format string to be parsed for this information.



CVS commit: src/lib/libc/stdio

2013-01-19 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sat Jan 19 15:25:58 UTC 2013

Modified Files:
src/lib/libc/stdio: printf.3

Log Message:
Fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/lib/libc/stdio/printf.3:1.59
--- src/lib/libc/stdio/printf.3:1.58	Sun Dec 26 12:39:54 2010
+++ src/lib/libc/stdio/printf.3	Sat Jan 19 15:25:58 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: printf.3,v 1.58 2010/12/26 12:39:54 jnemeth Exp $
+.\	$NetBSD: printf.3,v 1.59 2013/01/19 15:25:58 uwe Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -104,7 +104,7 @@ write output to the given output
 .Fn dprintf
 and
 .Fn vdprintf
-write output to the give file descriptor
+write output to the given file descriptor
 .Fa fd ;
 .Fn sprintf ,
 .Fn snprintf ,



CVS commit: src/lib/libc/stdio

2012-11-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov 15 03:50:36 UTC 2012

Modified Files:
src/lib/libc/stdio: flags.c fopen.3

Log Message:
Add 'x' to the mode bits to specify O_EXCL, like glibc.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdio/flags.c
cvs rdiff -u -r1.28 -r1.29 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.16 src/lib/libc/stdio/flags.c:1.17
--- src/lib/libc/stdio/flags.c:1.16	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/flags.c	Wed Nov 14 22:50:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 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.16 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -90,6 +90,7 @@ __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.
+	 * x means exclusive open.
 	 */
 	for (; *mode; mode++)
 		switch (*mode) {
@@ -103,6 +104,9 @@ __sflags(const char *mode, int *optr)
 		case 'e':
 			o |= O_CLOEXEC;
 			break;
+		case 'x':
+			o |= O_EXCL;
+			break;
 		case 'b':
 			break;
 		default:	/* We could produce a warning here */

Index: src/lib/libc/stdio/fopen.3
diff -u src/lib/libc/stdio/fopen.3:1.28 src/lib/libc/stdio/fopen.3:1.29
--- src/lib/libc/stdio/fopen.3:1.28	Mon Jul  2 16:02:43 2012
+++ src/lib/libc/stdio/fopen.3	Wed Nov 14 22:50:36 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: fopen.3,v 1.28 2012/07/02 20:02:43 wiz Exp $
+.\	$NetBSD: fopen.3,v 1.29 2012/11/15 03:50:36 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 July 18, 2011
+.Dd November 14, 2012
 .Dt FOPEN 3
 .Os
 .Sh NAME
@@ -117,6 +117,12 @@ will fail.
 This is a non
 .St -ansiC
 extension.
+.It Sq x
+The letter
+.Sq x
+in the mode turns on exclusive open mode to the file (
+.Dv O_EXCL )
+which means that the file will not be created if it already exists.
 .El
 .Pp
 Any created files will have mode



CVS commit: src/lib/libc/stdio

2012-07-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Jul  2 20:02:43 UTC 2012

Modified Files:
src/lib/libc/stdio: fopen.3

Log Message:
Sort description of flags.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/lib/libc/stdio/fopen.3:1.28
--- src/lib/libc/stdio/fopen.3:1.27	Mon Jul 18 05:17:16 2011
+++ src/lib/libc/stdio/fopen.3	Mon Jul  2 20:02:43 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: fopen.3,v 1.27 2011/07/18 05:17:16 jruoho Exp $
+.\	$NetBSD: fopen.3,v 1.28 2012/07/02 20:02:43 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -63,7 +63,13 @@ The argument
 .Fa mode
 points to a string beginning with one of the following
 sequences (Additional characters may follow these sequences.):
-.Bl -tag -width indent
+.Bl -tag -width 4n
+.It Dq Li a
+Append; open for writing.
+The file is created if it does not exist.
+.It Dq Li a+
+Append; open for reading and writing.
+The file is created if it does not exist.
 .It Dq Li r
 Open for reading.
 .It Dq Li r+
@@ -74,45 +80,38 @@ Truncate file to zero length or create f
 .It Dq Li w+
 Open for reading and writing.
 Truncate file to zero length or create file.
-.It Dq Li a
-Append; open for writing.
-The file is created if it does not exist.
-.It Dq Li a+
-Append; open for reading and writing.
-The file is created if it does not exist.
 .El
 .Pp
-Additionally:
-.Bl -bullet -offset 2n
-.It
-The
+Additionally, the
 .Fa mode
-string can also include the letter
-.Dq b
-either as a last character or
-as a character between the characters in any of the two-character strings
-described above.
+string can also include one of the following letters:
+.Bl -tag -width 4n
+.It Sq b
+The letter
+.Sq b
+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
-.Dq b
+.Sq b
 is ignored.
-.It
+.It Sq e
 The letter
-.Dq f
-in the mode string restricts
-.Fn fopen
-to regular files; if the file opened is not a regular file,
+.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.
 This is a non
 .St -ansiC
 extension.
-.It
+.It Sq f
 The letter
-.Dq 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,
+.Sq f
+in the mode string restricts
+.Fn fopen
+to regular files; if the file opened is not a regular file,
 .Fn fopen
 will fail.
 This is a non



CVS commit: src/lib/libc/stdio

2012-06-09 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Sat Jun  9 22:49:18 UTC 2012

Modified Files:
src/lib/libc/stdio: funopen.3

Log Message:
Consistently use major/minor for NetBSD version.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 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.20 src/lib/libc/stdio/funopen.3:1.21
--- src/lib/libc/stdio/funopen.3:1.20	Fri May 11 17:14:12 2012
+++ src/lib/libc/stdio/funopen.3	Sat Jun  9 22:49:18 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: funopen.3,v 1.20 2012/05/11 17:14:12 njoly Exp $
+.\	$NetBSD: funopen.3,v 1.21 2012/06/09 22:49:18 njoly Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -180,7 +180,7 @@ functions first appeared in
 The
 .Fn funopen2
 functions first appeared in
-.Nx 7 .
+.Nx 7.0 .
 .Sh CAVEATS
 All three functions are specific to
 .Nx



CVS commit: src/lib/libc/stdio

2012-03-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 29 14:27:34 UTC 2012

Modified Files:
src/lib/libc/stdio: fmemopen.c

Log Message:
The flush function makes the tests fail. So undo it for now until we decide
if the tests are wrong or the flushing is wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdio/fmemopen.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/fmemopen.c
diff -u src/lib/libc/stdio/fmemopen.c:1.7 src/lib/libc/stdio/fmemopen.c:1.8
--- src/lib/libc/stdio/fmemopen.c:1.7	Tue Mar 27 11:05:42 2012
+++ src/lib/libc/stdio/fmemopen.c	Thu Mar 29 10:27:33 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: fmemopen.c,v 1.7 2012/03/27 15:05:42 christos Exp $ */
+/* $NetBSD: fmemopen.c,v 1.8 2012/03/29 14:27:33 christos Exp $ */
 
 /*-
  * Copyright (c)2007, 2010 Takehiko NOZAKI,
@@ -29,7 +29,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: fmemopen.c,v 1.7 2012/03/27 15:05:42 christos Exp $);
+__RCSID($NetBSD: fmemopen.c,v 1.8 2012/03/29 14:27:33 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include assert.h
@@ -98,6 +98,7 @@ ok:
 	return (ssize_t)(p-cur - s);
 }
 
+#ifdef notyet
 static int
 fmemopen_flush(void *cookie)
 {
@@ -111,6 +112,7 @@ fmemopen_flush(void *cookie)
 	*p-cur = '\0';
 	return 0;
 }
+#endif
 
 static off_t
 fmemopen_seek(void *cookie, off_t offset, int whence)
@@ -221,7 +223,9 @@ fmemopen(void * __restrict buf, size_t s
 	fp-_write  = (flags  __SRD) ? NULL : fmemopen_write;
 	fp-_read   = (flags  __SWR) ? NULL : fmemopen_read;
 	fp-_seek   = fmemopen_seek;
+#ifdef notyet
 	fp-_flush  = fmemopen_flush;
+#endif
 	fp-_cookie = (void *)cookie;
 
 	return fp;



CVS commit: src/lib/libc/stdio

2012-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 28 15:21:11 UTC 2012

Modified Files:
src/lib/libc/stdio: funopen.c

Log Message:
only provide compatibility i/o functions to the ones provided by the caller.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdio/funopen.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/funopen.c
diff -u src/lib/libc/stdio/funopen.c:1.13 src/lib/libc/stdio/funopen.c:1.14
--- src/lib/libc/stdio/funopen.c:1.13	Tue Mar 27 11:05:42 2012
+++ src/lib/libc/stdio/funopen.c	Wed Mar 28 11:21:11 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: funopen.c,v 1.13 2012/03/27 15:05:42 christos Exp $	*/
+/*	$NetBSD: funopen.c,v 1.14 2012/03/28 15:21:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)funopen.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: funopen.c,v 1.13 2012/03/27 15:05:42 christos Exp $);
+__RCSID($NetBSD: funopen.c,v 1.14 2012/03/28 15:21:11 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -159,7 +159,12 @@ funopen(const void *cookie,
 	d-writefn = writefn;
 	d-seekfn = seekfn;
 	d-closefn = closefn;
-	fp = funopen2(d, creadfn, cwritefn, cseekfn, NULL, cclosefn);
+	fp = funopen2(d,
+	d-readfn ? creadfn : NULL,
+	d-writefn ? cwritefn : NULL,
+	d-seekfn ? cseekfn : NULL,
+	NULL,
+	d-closefn ? cclosefn : NULL);
 	if (fp != NULL)
 		return fp;
 	free(d);



CVS commit: src/lib/libc/stdio

2012-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar 27 15:05:43 UTC 2012

Modified Files:
src/lib/libc/stdio: Makefile.inc fflush.c findfp.c fmemopen.c freopen.c
fseeko.c ftell.c ftello.c funopen.3 funopen.c fvwrite.c local.h
refill.c sscanf.c stdio.c vfwprintf.c vsscanf.c vswscanf.c

Log Message:
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libc/stdio/Makefile.inc
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/fflush.c
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdio/findfp.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdio/fmemopen.c \
src/lib/libc/stdio/ftello.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdio/freopen.c \
src/lib/libc/stdio/funopen.3 src/lib/libc/stdio/vsscanf.c
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdio/fseeko.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdio/ftell.c \
src/lib/libc/stdio/sscanf.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/funopen.c
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdio/fvwrite.c
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/stdio/local.h
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/refill.c
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdio/stdio.c
cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdio/vfwprintf.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdio/vswscanf.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/Makefile.inc
diff -u src/lib/libc/stdio/Makefile.inc:1.40 src/lib/libc/stdio/Makefile.inc:1.41
--- src/lib/libc/stdio/Makefile.inc:1.40	Wed Dec 22 11:59:10 2010
+++ src/lib/libc/stdio/Makefile.inc	Tue Mar 27 11:05:42 2012
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	5.7 (Berkeley) 6/27/91
-#	$NetBSD: Makefile.inc,v 1.40 2010/12/22 16:59:10 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.41 2012/03/27 15:05:42 christos Exp $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
@@ -45,6 +45,7 @@ MLINKS+=fread.3 fwrite.3
 MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \
 	fseek.3 ftello.3 fseek.3 rewind.3
 MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3
+MLINKS+=funopen.3 funopen2.3 funopen.3 fropen2.3 funopen.3 fwopen2.3
 MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \
 	getc.3 getchar_unlocked.3 getc.3 getw.3
 MLINKS+=getdelim.3 getline.3

Index: src/lib/libc/stdio/fflush.c
diff -u src/lib/libc/stdio/fflush.c:1.17 src/lib/libc/stdio/fflush.c:1.18
--- src/lib/libc/stdio/fflush.c:1.17	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/fflush.c	Tue Mar 27 11:05:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fflush.c,v 1.17 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 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.17 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -80,7 +80,8 @@ int
 __sflush(FILE *fp)
 {
 	unsigned char *p;
-	int n, t;
+	size_t n;
+	ssize_t t;
 
 	_DIAGASSERT(fp != NULL);
 
@@ -92,8 +93,8 @@ __sflush(FILE *fp)
 		return 0;
 
 	ptrdiff_t tp = fp-_p - p;
-	_DIAGASSERT(__type_fit(int, tp));
-	n = (int)tp;		/* write this much */
+	_DIAGASSERT(__type_fit(ssize_t, tp));
+	n = (ssize_t)tp;	/* write this much */
 
 	/*
 	 * Set these immediately to avoid problems with longjmp and to allow
@@ -109,5 +110,7 @@ __sflush(FILE *fp)
 			return EOF;
 		}
 	}
+	if (fp-_flush)
+		return (*fp-_flush)(fp-_cookie);
 	return 0;
 }

Index: src/lib/libc/stdio/findfp.c
diff -u src/lib/libc/stdio/findfp.c:1.27 src/lib/libc/stdio/findfp.c:1.28
--- src/lib/libc/stdio/findfp.c:1.27	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/findfp.c	Tue Mar 27 11:05:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: findfp.c,v 1.27 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: findfp.c,v 1.28 2012/03/27 15:05:42 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)findfp.c	8.2 (Berkeley) 1/4/94;
 #else
-__RCSID($NetBSD: findfp.c,v 1.27 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: findfp.c,v 1.28 2012/03/27 15:05:42 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -56,13 +56,29 @@ int	__sdidinit;
 
 #define	NDYNAMIC 10		/* add ten more whenever necessary */
 
-#define	std(flags, file) \
-/*	  p r  w  flags  file  bf lfbsize  cookie   close */ \
-	{ NULL, 0, 0, flags, file, { NULL, 0 }, 0, __sF + file, __sclose, \
-/*	  read  seek write ext  up */ \
-	  __sread,  __sseek, __swrite, { (void *)(__sFext + file), 0 }, NULL, \
-/*	  ur ubuf, nbuf  lb blksize  offset */ \
-	  0, { '\0', '\0', '\0' }, 

CVS commit: src/lib/libc/stdio

2012-03-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 21 14:20:47 UTC 2012

Modified Files:
src/lib/libc/stdio: vfwprintf.c

Log Message:
unsigned char portability casts


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 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.28 src/lib/libc/stdio/vfwprintf.c:1.29
--- src/lib/libc/stdio/vfwprintf.c:1.28	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/vfwprintf.c	Wed Mar 21 10:20:47 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.28 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.29 2012/03/21 14:20:47 christos 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.28 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: vfwprintf.c,v 1.29 2012/03/21 14:20:47 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -290,8 +290,9 @@ __ultoa(u_long val, CHAR_T *endp, int ba
 			 * If (*grp == CHAR_MAX) then no more grouping
 			 * should be performed.
 			 */
-			if (needgrp  ndig == *grp  *grp != CHAR_MAX
-	 sval  9) {
+			if (needgrp  ndig == *grp
+			 (unsigned char)*grp != (unsigned char)CHAR_MAX
+			 sval  9) {
 *--cp = thousep;
 ndig = 0;
 /*
@@ -362,8 +363,10 @@ __ujtoa(uintmax_t val, CHAR_T *endp, int
 			 * If (*grp == CHAR_MAX) then no more grouping
 			 * should be performed.
 			 */
-			if (needgrp  *grp != CHAR_MAX  ndig == *grp
-	 sval  9) {
+			if (needgrp
+			 (unsigned char)*grp != (unsigned char)CHAR_MAX
+			 ndig == *grp
+			 sval  9) {
 *--cp = thousep;
 ndig = 0;
 /*
@@ -1240,7 +1243,8 @@ fp_common:
 	/* space for thousands' grouping */
 	nseps = nrepeats = 0;
 	lead = expt;
-	while (*grouping != CHAR_MAX) {
+	while ((unsigned char)*grouping
+	!= (unsigned char)CHAR_MAX) {
 		if (lead = *grouping)
 			break;
 		lead -= *grouping;



CVS commit: src/lib/libc/stdio

2012-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar 20 01:42:59 UTC 2012

Modified Files:
src/lib/libc/stdio: stdio.c

Log Message:
ansi prototype


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdio/stdio.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/stdio.c
diff -u src/lib/libc/stdio/stdio.c:1.19 src/lib/libc/stdio/stdio.c:1.20
--- src/lib/libc/stdio/stdio.c:1.19	Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/stdio.c	Mon Mar 19 21:42:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: stdio.c,v 1.19 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: stdio.c,v 1.20 2012/03/20 01:42:59 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)stdio.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: stdio.c,v 1.19 2012/03/15 18:22:30 christos Exp $);
+__RCSID($NetBSD: stdio.c,v 1.20 2012/03/20 01:42:59 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -108,8 +108,7 @@ __sseek(void *cookie, off_t offset, int 
 }
 
 int
-__sclose(cookie)
-	void *cookie;
+__sclose(void *cookie)
 {
 
 	_DIAGASSERT(cookie != NULL);



CVS commit: src/lib/libc/stdio

2012-03-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 15 11:46:08 UTC 2012

Modified Files:
src/lib/libc/stdio: local.h

Log Message:
ansi prototypes.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdio/local.h

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/local.h
diff -u src/lib/libc/stdio/local.h:1.31 src/lib/libc/stdio/local.h:1.32
--- src/lib/libc/stdio/local.h:1.31	Sun Jan 22 13:36:17 2012
+++ src/lib/libc/stdio/local.h	Thu Mar 15 07:46:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: local.h,v 1.31 2012/01/22 18:36:17 christos Exp $	*/
+/*	$NetBSD: local.h,v 1.32 2012/03/15 11:46:08 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -46,47 +46,44 @@
  * in particular, macros and private variables.
  */
 
-extern int	__sflush __P((FILE *));
-extern FILE	*__sfp __P((void));
-extern void	__sfpinit __P((FILE *));
-extern int	__srefill __P((FILE *));
-extern int	__sread __P((void *, char *, int));
-extern int	__swrite __P((void *, char const *, int));
-extern off_t	__sseek __P((void *, off_t, int));
-extern int	__sclose __P((void *));
-extern void	__sinit __P((void));
-extern void	_cleanup __P((void));
-extern void	(*__cleanup) __P((void));
-extern void	__smakebuf __P((FILE *));
-extern int	__swhatbuf __P((FILE *, size_t *, int *));
-extern int	_fwalk __P((int (*)(FILE *)));
-extern char	*_mktemp __P((char *));
-extern int	__swsetup __P((FILE *));
-extern int	__sflags __P((const char *, int *));
-extern int	__svfscanf __P((FILE * __restrict, const char * __restrict,
-		va_list))
-		__attribute__((__format__(__scanf__, 2, 0)));
-extern int	__svfscanf_unlocked __P((FILE * __restrict, const char * __restrict,
-		va_list))
-		__attribute__((__format__(__scanf__, 2, 0)));
-extern int	__vfprintf_unlocked __P((FILE * __restrict, const char * __restrict,
-		va_list));
+extern int	__sflush(FILE *);
+extern FILE	*__sfp(void);
+extern void	__sfpinit(FILE *);
+extern int	__srefill(FILE *);
+extern int	__sread(void *, char *, int);
+extern int	__swrite(void *, char * const, int);
+extern off_t	__sseek(void *, off_t, int);
+extern int	__sclose(void *);
+extern void	__sinit(void);
+extern void	_cleanup(void);
+extern void	(*__cleanup)(void);
+extern void	__smakebuf(FILE *);
+extern int	__swhatbuf(FILE *, size_t *, int *);
+extern int	_fwalk(int (*)(FILE *));
+extern char	*_mktemp(char *);
+extern int	__swsetup(FILE *);
+extern int	__sflags(const char *, int *);
+extern int	__svfscanf(FILE * __restrict, const char * __restrict,
+va_list) __scanflike(2, 0);
+extern int	__svfscanf_unlocked(FILE * __restrict, const char * __restrict,
+va_list) __scanflike(2, 0);
+extern int	__vfprintf_unlocked(FILE * __restrict, const char * __restrict,
+va_list) __printflike(2, 0);
 
 
 extern int	__sdidinit;
 
-extern int	__gettemp __P((char *, int *, int));
+extern int	__gettemp(char *, int *, int);
 
-extern wint_t	__fgetwc_unlock __P((FILE *));
-extern wint_t	__fputwc_unlock __P((wchar_t, FILE *));
+extern wint_t	__fgetwc_unlock(FILE *);
+extern wint_t	__fputwc_unlock(wchar_t, FILE *);
 
 extern ssize_t	__getdelim(char **__restrict, size_t *__restrict, int,
 FILE *__restrict);
-extern char	*__fgetstr __P((FILE * __restrict, size_t * __restrict, int));
-extern int 	 __vfwprintf_unlocked __P((FILE *, const wchar_t *,
-va_list));
-extern int	 __vfwscanf_unlocked __P((FILE * __restrict,
-const wchar_t * __restrict, va_list));
+extern char	*__fgetstr(FILE * __restrict, size_t * __restrict, int);
+extern int 	 __vfwprintf_unlocked(FILE *, const wchar_t *, va_list);
+extern int	 __vfwscanf_unlocked(FILE * __restrict,
+const wchar_t * __restrict, va_list);
 
 /*
  * Return true iff the given FILE cannot be written now.
@@ -115,8 +112,8 @@ extern int	 __vfwscanf_unlocked __P((FIL
 	_EXT(fp)-_fgetstr_len = 0; \
 }
 
-extern void __flockfile_internal __P((FILE *, int));
-extern void __funlockfile_internal __P((FILE *, int));
+extern void __flockfile_internal(FILE *, int);
+extern void __funlockfile_internal(FILE *, int);
 
 /*
  * Detect if the current file position fits in a long int.



CVS commit: src/lib/libc/stdio

2012-03-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 15 13:23:10 UTC 2012

Modified Files:
src/lib/libc/stdio: local.h

Log Message:
fix signature.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/local.h

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/local.h
diff -u src/lib/libc/stdio/local.h:1.32 src/lib/libc/stdio/local.h:1.33
--- src/lib/libc/stdio/local.h:1.32	Thu Mar 15 07:46:08 2012
+++ src/lib/libc/stdio/local.h	Thu Mar 15 09:23:10 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: local.h,v 1.32 2012/03/15 11:46:08 christos Exp $	*/
+/*	$NetBSD: local.h,v 1.33 2012/03/15 13:23:10 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -51,7 +51,7 @@ extern FILE	*__sfp(void);
 extern void	__sfpinit(FILE *);
 extern int	__srefill(FILE *);
 extern int	__sread(void *, char *, int);
-extern int	__swrite(void *, char * const, int);
+extern int	__swrite(void *, char const *, int);
 extern off_t	__sseek(void *, off_t, int);
 extern int	__sclose(void *);
 extern void	__sinit(void);



CVS commit: src/lib/libc/stdio

2012-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 17 19:57:53 UTC 2012

Modified Files:
src/lib/libc/stdio: vfwprintf.c

Log Message:
Fix: CVE-2012-0864 fprintf() positional argument abuse.
Described in: http://www.phrack.org/issues.html?issue=67id=9#article
Reported by Stefan Cornelius / Red Hat Security Response Team

- convert internal positional arguments bookkeeping from int to size_t
- provide overflow protection in positional argument spec
- convert loops to memset
- fix memory leaks
- limit positional argument stack offset to the number of arguments required
  by the printf to avoid coredump from va_arg() exhaustion.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 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.24 src/lib/libc/stdio/vfwprintf.c:1.25
--- src/lib/libc/stdio/vfwprintf.c:1.24	Wed Aug 17 05:53:54 2011
+++ src/lib/libc/stdio/vfwprintf.c	Fri Feb 17 14:57:53 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.24 2011/08/17 09:53:54 christos Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.25 2012/02/17 19:57:53 christos 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.24 2011/08/17 09:53:54 christos Exp $);
+__RCSID($NetBSD: vfwprintf.c,v 1.25 2012/02/17 19:57:53 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -124,7 +124,7 @@ union arg {
  * Type ids for argument type table.
  */
 enum typeid {
-	T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT,
+	T_UNUSED = 0, TP_SHORT, T_INT, T_U_INT, TP_INT,
 	T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
 	T_PTRDIFFT, TP_PTRDIFFT, T_SSIZET, T_SIZET, TP_SIZET,
 	T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
@@ -144,7 +144,7 @@ static char	*__wcsconv(wchar_t *, int);
 static int	__sprint(FILE *, struct __suio *);
 #endif
 static int	__find_arguments(const CHAR_T *, va_list, union arg **);
-static int	__grow_type_table(int, enum typeid **, int *);
+static int	__grow_type_table(size_t, enum typeid **, size_t *);
 
 /*
  * Helper function for `fprintf to unbuffered unix file': creates a
@@ -1554,20 +1554,27 @@ __find_arguments(const CHAR_T *fmt0, va_
 {
 	CHAR_T *fmt;		/* format string */
 	int ch;			/* character from fmt */
-	int n, n2;		/* handy integer (short term usage) */
+	size_t n, n2;		/* handy index (short term usage) */
 	CHAR_T *cp;		/* handy char pointer (short term usage) */
 	int flags;		/* flags as above */
 	enum typeid *typetable; /* table of types */
 	enum typeid stattypetable [STATIC_ARG_TBL_SIZE];
-	int tablesize;		/* current size of type table */
-	int tablemax;		/* largest used index in table */
-	int nextarg;		/* 1-based argument index */
+	size_t tablesize;	/* current size of type table */
+	size_t tablemax;	/* largest used index in table */
+	size_t nextarg;		/* 1-based argument index */
+	size_t nitems;		/* number of items we picked from the stack */
 
 	/*
 	 * Add an argument type to the table, expanding if necessary.
+	 * Check for overflow.
 	 */
 #define ADDTYPE(type) \
 	do { \
+		if (nextarg  SIZE_MAX / sizeof(**argtable)) { \
+			if (typetable != stattypetable) \
+free(typetable); \
+			return -1; \
+		} \
 		if (nextarg = tablesize) \
 			if (__grow_type_table(nextarg, typetable, \
 			tablesize) == -1) \
@@ -1575,6 +1582,7 @@ __find_arguments(const CHAR_T *fmt0, va_
 		if (nextarg  tablemax) \
 			tablemax = nextarg; \
 		typetable[nextarg++] = type; \
+		nitems++; \
 	} while (/*CONSTCOND*/0)
 
 #define	ADDSARG() \
@@ -1619,7 +1627,7 @@ __find_arguments(const CHAR_T *fmt0, va_
 		cp++; \
 	} \
 	if (*cp == '$') { \
-		int hold = nextarg; \
+		size_t hold = nextarg; \
 		nextarg = n2; \
 		ADDTYPE(T_INT); \
 		nextarg = hold; \
@@ -1628,12 +1636,12 @@ __find_arguments(const CHAR_T *fmt0, va_
 		ADDTYPE(T_INT); \
 	}
 	fmt = (CHAR_T *)__UNCONST(fmt0);
+	memset(stattypetable, 0, sizeof(stattypetable));
 	typetable = stattypetable;
 	tablesize = STATIC_ARG_TBL_SIZE;
 	tablemax = 0; 
 	nextarg = 1;
-	for (n = 0; n  STATIC_ARG_TBL_SIZE; n++)
-		typetable[n] = T_UNUSED;
+	nitems = 1;
 
 	/*
 	 * Scan the format for conversions (`%' character).
@@ -1795,13 +1803,30 @@ reswitch:	switch (ch) {
 	}
 done:
 	/*
+	 * nitems contains the number of arguments we picked from the stack.
+	 * If tablemax is larger, this means that some positional argument,
+	 * tried to pick an argument the number of arguments possibly supplied.
+	 * Since positional arguments are typically used to swap the order of
+	 * the printf arguments and not to pick random arguments from strange
+	 * positions in the stack, we assume that if the positional argument
+	 * is trying to pick 

CVS commit: src/lib/libc/stdio

2012-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 17 23:58:36 UTC 2012

Modified Files:
src/lib/libc/stdio: vfwprintf.c

Log Message:
remove unused variable


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 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.25 src/lib/libc/stdio/vfwprintf.c:1.26
--- src/lib/libc/stdio/vfwprintf.c:1.25	Fri Feb 17 14:57:53 2012
+++ src/lib/libc/stdio/vfwprintf.c	Fri Feb 17 18:58:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.25 2012/02/17 19:57:53 christos Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.26 2012/02/17 23:58:36 christos 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.25 2012/02/17 19:57:53 christos Exp $);
+__RCSID($NetBSD: vfwprintf.c,v 1.26 2012/02/17 23:58:36 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1931,7 +1931,7 @@ __grow_type_table (size_t nextarg, enum 
 	enum typeid *const oldtable = *typetable;
 	const int oldsize = *tablesize;
 	enum typeid *newtable;
-	size_t n, newsize = oldsize * 2;
+	size_t newsize = oldsize * 2;
 
 	if (newsize  nextarg + 1)
 		newsize = nextarg + 1;



  1   2   >