Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdio Add FLOCKFILE() locking - should be threadsaf...
details: https://anonhg.NetBSD.org/src/rev/c7034610d49c
branches: trunk
changeset: 566478:c7034610d49c
user: drochner <drochner%NetBSD.org@localhost>
date: Mon May 10 16:50:23 2004 +0000
description:
Add FLOCKFILE() locking - should be threadsafe now.
(Didn't test the !HAVE_FPARSELN && !_REENTRANT case -- this might be
hit in tools/compat on some host platforms.)
diffstat:
lib/libc/stdio/fparseln.c | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
diffs (68 lines):
diff -r e110f08a47de -r c7034610d49c lib/libc/stdio/fparseln.c
--- a/lib/libc/stdio/fparseln.c Mon May 10 16:47:11 2004 +0000
+++ b/lib/libc/stdio/fparseln.c Mon May 10 16:50:23 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fparseln.c,v 1.2 2003/01/18 11:29:52 thorpej Exp $ */
+/* $NetBSD: fparseln.c,v 1.3 2004/05/10 16:50:23 drochner Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fparseln.c,v 1.2 2003/01/18 11:29:52 thorpej Exp $");
+__RCSID("$NetBSD: fparseln.c,v 1.3 2004/05/10 16:50:23 drochner Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -48,6 +48,15 @@
#if ! HAVE_FPARSELN
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef _REENTRANT
+#define __fgetln(f, l) __fgetstr(f, l, '\n')
+#else
+#define __fgetln(f, l) fgetln(f, l)
+#endif
+
static int isescaped(const char *, const char *, int);
/* isescaped():
@@ -110,13 +119,15 @@
*/
nl = '\n';
+ FLOCKFILE(fp);
+
while (cnt) {
cnt = 0;
if (lineno)
(*lineno)++;
- if ((ptr = fgetln(fp, &s)) == NULL)
+ if ((ptr = __fgetln(fp, &s)) == NULL)
break;
if (s && com) { /* Check and eliminate comments */
@@ -148,6 +159,7 @@
continue;
if ((cp = realloc(buf, len + s + 1)) == NULL) {
+ FUNLOCKFILE(fp);
free(buf);
return NULL;
}
@@ -158,6 +170,8 @@
buf[len] = '\0';
}
+ FUNLOCKFILE(fp);
+
if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
strchr(buf, esc) != NULL) {
ptr = cp = buf;
Home |
Main Index |
Thread Index |
Old Index