Deleted Added
full compact
fclose.c (225736) fclose.c (234871)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: stable/9/lib/libc/stdio/fclose.c 165903 2007-01-09 00:28:16Z imp $");
37__FBSDID("$FreeBSD: stable/9/lib/libc/stdio/fclose.c 234871 2012-05-01 10:49:20Z kib $");
38
39#include "namespace.h"
40#include <errno.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include "un-namespace.h"
38
39#include "namespace.h"
40#include <errno.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include "un-namespace.h"
44#include <spinlock.h>
44#include "libc_private.h"
45#include "local.h"
46
47int
48fclose(FILE *fp)
49{
50 int r;
51

--- 8 unchanged lines hidden (view full) ---

60 if (fp->_flags & __SMBF)
61 free((char *)fp->_bf._base);
62 if (HASUB(fp))
63 FREEUB(fp);
64 if (HASLB(fp))
65 FREELB(fp);
66 fp->_file = -1;
67 fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
45#include "libc_private.h"
46#include "local.h"
47
48int
49fclose(FILE *fp)
50{
51 int r;
52

--- 8 unchanged lines hidden (view full) ---

61 if (fp->_flags & __SMBF)
62 free((char *)fp->_bf._base);
63 if (HASUB(fp))
64 FREEUB(fp);
65 if (HASLB(fp))
66 FREELB(fp);
67 fp->_file = -1;
68 fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
69
70 /*
71 * Lock the spinlock used to protect __sglue list walk in
72 * __sfp(). The __sfp() uses fp->_flags == 0 test as an
73 * indication of the unused FILE.
74 *
75 * Taking the lock prevents possible compiler or processor
76 * reordering of the writes performed before the final _flags
77 * cleanup, making sure that we are done with the FILE before
78 * it is considered available.
79 */
80 STDIO_THREAD_LOCK();
68 fp->_flags = 0; /* Release this FILE for reuse. */
81 fp->_flags = 0; /* Release this FILE for reuse. */
82 STDIO_THREAD_UNLOCK();
69 FUNLOCKFILE(fp);
70 return (r);
71}
83 FUNLOCKFILE(fp);
84 return (r);
85}