Module Name:    src
Committed By:   roy
Date:           Wed Dec  2 09:03:13 UTC 2009

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

Log Message:
Reinstate __getdelim which does no locking.
Callers are now required to FLOCKFILE so they can operate on fp as well.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fgetln.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdio/fgetstr.c \
    src/lib/libc/stdio/getdelim.c
cvs rdiff -u -r1.22 -r1.23 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/fgetln.c
diff -u src/lib/libc/stdio/fgetln.c:1.15 src/lib/libc/stdio/fgetln.c:1.16
--- src/lib/libc/stdio/fgetln.c:1.15	Thu Sep 24 20:38:53 2009
+++ src/lib/libc/stdio/fgetln.c	Wed Dec  2 09:03:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fgetln.c,v 1.15 2009/09/24 20:38:53 roy Exp $	*/
+/*	$NetBSD: fgetln.c,v 1.16 2009/12/02 09:03:13 roy Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -33,13 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)fgetline.c	8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: fgetln.c,v 1.15 2009/09/24 20:38:53 roy Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
+__RCSID("$NetBSD: fgetln.c,v 1.16 2009/12/02 09:03:13 roy Exp $");
 
 #include "namespace.h"
 
@@ -53,17 +47,18 @@
 #endif
 
 /*
- * Get an input line.  The returned pointer often (but not always)
- * points into a stdio buffer.  Fgetline does not alter the text of
- * the returned line (which is thus not a C string because it will
- * not necessarily end with '\0'), but does allow callers to modify
- * it if they wish.  Thus, we set __SMOD in case the caller does.
+ * 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
+ * on this is non portable - better to use the POSIX getdelim(3) function.
  */
 char *
-fgetln(fp, lenp)
-	FILE *fp;
-	size_t *lenp;
+fgetln(FILE *fp, size_t *lenp)
 {
+	char *p;
 	
-	return __fgetstr(fp, lenp, '\n');
+	FLOCKFILE(fp);
+	p = __fgetstr(fp, lenp, '\n');
+	FUNLOCKFILE(fp);
+	return p;
 }

Index: src/lib/libc/stdio/fgetstr.c
diff -u src/lib/libc/stdio/fgetstr.c:1.9 src/lib/libc/stdio/fgetstr.c:1.10
--- src/lib/libc/stdio/fgetstr.c:1.9	Tue Dec  1 00:03:53 2009
+++ src/lib/libc/stdio/fgetstr.c	Wed Dec  2 09:03:13 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fgetstr.c,v 1.9 2009/12/01 00:03:53 roy Exp $	*/
+/* $NetBSD: fgetstr.c,v 1.10 2009/12/02 09:03:13 roy Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fgetstr.c,v 1.9 2009/12/01 00:03:53 roy Exp $");
+__RCSID("$NetBSD: fgetstr.c,v 1.10 2009/12/02 09:03:13 roy Exp $");
 
 #include "namespace.h"
 
@@ -58,7 +58,7 @@
 
 	p = (char *)fp->_lb._base;
 	size = fp->_lb._size;
-	n = getdelim(&p, &size, sep, fp);
+	n = __getdelim(&p, &size, sep, fp);
 	fp->_lb._base = (unsigned char *)p;
 	/* The struct size variable is only an int .....
 	 * This still works when exceeded, but the buffer could be
@@ -69,7 +69,7 @@
 		fp->_lb._size = (int)size;
 	if (n == -1) {
 		*lenp = 0;
-		if (errno == EOVERFLOW) /* fixup errno */
+		if (__sferror(fp) && errno == EOVERFLOW) /* fixup errno */
 			errno = EINVAL;
 		return NULL;
 	}
Index: src/lib/libc/stdio/getdelim.c
diff -u src/lib/libc/stdio/getdelim.c:1.9 src/lib/libc/stdio/getdelim.c:1.10
--- src/lib/libc/stdio/getdelim.c:1.9	Tue Dec  1 00:52:13 2009
+++ src/lib/libc/stdio/getdelim.c	Wed Dec  2 09:03:13 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: getdelim.c,v 1.9 2009/12/01 00:52:13 roy Exp $ */
+/* $NetBSD: getdelim.c,v 1.10 2009/12/02 09:03:13 roy Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: getdelim.c,v 1.9 2009/12/01 00:52:13 roy Exp $");
+__RCSID("$NetBSD: getdelim.c,v 1.10 2009/12/02 09:03:13 roy Exp $");
 
 #include "namespace.h"
 
@@ -54,7 +54,7 @@
 #define MINBUF	128
 
 ssize_t
-getdelim(char **__restrict buf, size_t *__restrict buflen,
+__getdelim(char **__restrict buf, size_t *__restrict buflen,
     int sep, FILE *__restrict fp)
 {
 	unsigned char *p;
@@ -72,7 +72,6 @@
 	if (*buf == NULL)
 		*buflen = 0;
 
-	FLOCKFILE(fp);
 	_SET_ORIENTATION(fp, -1);
 	off = 0;
 	do {
@@ -127,7 +126,6 @@
 		fp->_p += (int)len;
 		off += len;
 	} while (p == NULL);
-	FUNLOCKFILE(fp);
 
 	/* POSIX demands we return -1 on EOF. */
 	if (off == 0) 
@@ -139,6 +137,17 @@
 
 error:
 	fp->_flags |= __SERR;
-	FUNLOCKFILE(fp);
 	return -1;
 }
+
+ssize_t
+getdelim(char **__restrict buf, size_t *__restrict buflen,
+    int sep, FILE *__restrict fp)
+{
+	ssize_t n;
+
+	FLOCKFILE(fp);
+	n = __getdelim(buf, buflen, sep, fp);
+	FUNLOCKFILE(fp);
+	return n;
+}

Index: src/lib/libc/stdio/local.h
diff -u src/lib/libc/stdio/local.h:1.22 src/lib/libc/stdio/local.h:1.23
--- src/lib/libc/stdio/local.h:1.22	Tue Dec  1 00:03:53 2009
+++ src/lib/libc/stdio/local.h	Wed Dec  2 09:03:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: local.h,v 1.22 2009/12/01 00:03:53 roy Exp $	*/
+/*	$NetBSD: local.h,v 1.23 2009/12/02 09:03:13 roy Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -75,6 +75,8 @@
 extern wint_t	__fgetwc_unlock __P((FILE *));
 extern wint_t	__fputwc_unlock __P((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 *,
     _BSD_VA_LIST_));

Reply via email to