fclose.c (71579) | fclose.c (72373) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) 38#if 0 39static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; 40#endif 41static const char rcsid[] = | 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 --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) 38#if 0 39static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; 40#endif 41static const char rcsid[] = |
42 "$FreeBSD: head/lib/libc/stdio/fclose.c 71579 2001-01-24 13:01:12Z deischen $"; | 42 "$FreeBSD: head/lib/libc/stdio/fclose.c 72373 2001-02-11 22:06:43Z deischen $"; |
43#endif /* LIBC_SCCS and not lint */ 44 45#include "namespace.h" 46#include <errno.h> 47#include <stdio.h> 48#include <stdlib.h> 49#include "un-namespace.h" 50#include "libc_private.h" 51#include "local.h" 52 53int | 43#endif /* LIBC_SCCS and not lint */ 44 45#include "namespace.h" 46#include <errno.h> 47#include <stdio.h> 48#include <stdlib.h> 49#include "un-namespace.h" 50#include "libc_private.h" 51#include "local.h" 52 53int |
54fclose(fp) 55 FILE *fp; | 54fclose(FILE *fp) |
56{ 57 int r; 58 59 if (fp->_flags == 0) { /* not open! */ 60 errno = EBADF; 61 return (EOF); 62 } 63 FLOCKFILE(fp); 64 r = fp->_flags & __SWR ? __sflush(fp) : 0; 65 if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) 66 r = EOF; 67 if (fp->_flags & __SMBF) 68 free((char *)fp->_bf._base); 69 if (HASUB(fp)) 70 FREEUB(fp); 71 if (HASLB(fp)) 72 FREELB(fp); | 55{ 56 int r; 57 58 if (fp->_flags == 0) { /* not open! */ 59 errno = EBADF; 60 return (EOF); 61 } 62 FLOCKFILE(fp); 63 r = fp->_flags & __SWR ? __sflush(fp) : 0; 64 if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) 65 r = EOF; 66 if (fp->_flags & __SMBF) 67 free((char *)fp->_bf._base); 68 if (HASUB(fp)) 69 FREEUB(fp); 70 if (HASLB(fp)) 71 FREELB(fp); |
73 FUNLOCKFILE(fp); | |
74 fp->_file = -1; 75 fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ | 72 fp->_file = -1; 73 fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ |
76#if 0 77 if (fp->_lock != NULL) { 78 _pthread_mutex_destroy((pthread_mutex_t *)&fp->_lock); 79 fp->_lock = NULL; 80 } 81#endif | |
82 fp->_flags = 0; /* Release this FILE for reuse. */ | 74 fp->_flags = 0; /* Release this FILE for reuse. */ |
75 FUNLOCKFILE(fp); |
|
83 return (r); 84} | 76 return (r); 77} |