Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdio Do the lock *after* checking that the fp is v...
details: https://anonhg.NetBSD.org/src/rev/6f82ab99ceb5
branches: trunk
changeset: 480846:6f82ab99ceb5
user: mycroft <mycroft%NetBSD.org@localhost>
date: Fri Jan 21 19:53:02 2000 +0000
description:
Do the lock *after* checking that the fp is valid.
diffstat:
lib/libc/stdio/fclose.c | 10 +++++-----
lib/libc/stdio/fpurge.c | 12 +++++-------
2 files changed, 10 insertions(+), 12 deletions(-)
diffs (78 lines):
diff -r 7a2c23a72df7 -r 6f82ab99ceb5 lib/libc/stdio/fclose.c
--- a/lib/libc/stdio/fclose.c Fri Jan 21 19:51:36 2000 +0000
+++ b/lib/libc/stdio/fclose.c Fri Jan 21 19:53:02 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fclose.c,v 1.12 1999/09/20 04:39:25 lukem Exp $ */
+/* $NetBSD: fclose.c,v 1.13 2000/01/21 19:53:02 mycroft Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
#endif
-__RCSID("$NetBSD: fclose.c,v 1.12 1999/09/20 04:39:25 lukem Exp $");
+__RCSID("$NetBSD: fclose.c,v 1.13 2000/01/21 19:53:02 mycroft Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
@@ -59,12 +59,11 @@
_DIAGASSERT(fp != NULL);
- FLOCKFILE(fp);
if (fp->_flags == 0) { /* not open! */
errno = EBADF;
- FUNLOCKFILE(fp);
return (EOF);
}
+ FLOCKFILE(fp);
r = fp->_flags & __SWR ? __sflush(fp) : 0;
if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
r = EOF;
@@ -74,8 +73,9 @@
FREEUB(fp);
if (HASLB(fp))
FREELB(fp);
+ FUNLOCKFILE(fp);
+ fp->_file = -1;
fp->_flags = 0; /* Release this FILE for reuse. */
fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
- FUNLOCKFILE(fp);
return (r);
}
diff -r 7a2c23a72df7 -r 6f82ab99ceb5 lib/libc/stdio/fpurge.c
--- a/lib/libc/stdio/fpurge.c Fri Jan 21 19:51:36 2000 +0000
+++ b/lib/libc/stdio/fpurge.c Fri Jan 21 19:53:02 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fpurge.c,v 1.9 1999/09/20 04:39:28 lukem Exp $ */
+/* $NetBSD: fpurge.c,v 1.10 2000/01/21 19:53:03 mycroft Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: fpurge.c,v 1.9 1999/09/20 04:39:28 lukem Exp $");
+__RCSID("$NetBSD: fpurge.c,v 1.10 2000/01/21 19:53:03 mycroft Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -63,13 +63,11 @@
_DIAGASSERT(fp != NULL);
- FLOCKFILE(fp);
- if (!fp->_flags) {
+ if (fp->_flags == 0) {
errno = EBADF;
- FUNLOCKFILE(fp);
- return(EOF);
+ return (EOF);
}
-
+ FLOCKFILE(fp);
if (HASUB(fp))
FREEUB(fp);
fp->_p = fp->_bf._base;
Home |
Main Index |
Thread Index |
Old Index