Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdio Reinstate __getdelim which does no locking.
details: https://anonhg.NetBSD.org/src/rev/8e8409682a0e
branches: trunk
changeset: 749544:8e8409682a0e
user: roy <roy%NetBSD.org@localhost>
date: Wed Dec 02 09:03:13 2009 +0000
description:
Reinstate __getdelim which does no locking.
Callers are now required to FLOCKFILE so they can operate on fp as well.
diffstat:
lib/libc/stdio/fgetln.c | 29 ++++++++++++-----------------
lib/libc/stdio/fgetstr.c | 8 ++++----
lib/libc/stdio/getdelim.c | 21 +++++++++++++++------
lib/libc/stdio/local.h | 4 +++-
4 files changed, 34 insertions(+), 28 deletions(-)
diffs (168 lines):
diff -r 5e2d2c1005fa -r 8e8409682a0e lib/libc/stdio/fgetln.c
--- a/lib/libc/stdio/fgetln.c Wed Dec 02 08:53:03 2009 +0000
+++ b/lib/libc/stdio/fgetln.c Wed Dec 02 09:03:13 2009 +0000
@@ -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;
}
diff -r 5e2d2c1005fa -r 8e8409682a0e lib/libc/stdio/fgetstr.c
--- a/lib/libc/stdio/fgetstr.c Wed Dec 02 08:53:03 2009 +0000
+++ b/lib/libc/stdio/fgetstr.c Wed Dec 02 09:03:13 2009 +0000
@@ -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;
}
diff -r 5e2d2c1005fa -r 8e8409682a0e lib/libc/stdio/getdelim.c
--- a/lib/libc/stdio/getdelim.c Wed Dec 02 08:53:03 2009 +0000
+++ b/lib/libc/stdio/getdelim.c Wed Dec 02 09:03:13 2009 +0000
@@ -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;
+}
diff -r 5e2d2c1005fa -r 8e8409682a0e lib/libc/stdio/local.h
--- a/lib/libc/stdio/local.h Wed Dec 02 08:53:03 2009 +0000
+++ b/lib/libc/stdio/local.h Wed Dec 02 09:03:13 2009 +0000
@@ -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_));
Home |
Main Index |
Thread Index |
Old Index