]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/iofclose.c
Remove __get_clockfreq
[thirdparty/glibc.git] / libio / iofclose.c
CommitLineData
04277e02 1/* Copyright (C) 1993-2019 Free Software Foundation, Inc.
41bdb6e2 2 This file is part of the GNU C Library.
40a55d20 3
41bdb6e2
AJ
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
40a55d20 8
41bdb6e2
AJ
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
40a55d20 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2
AJ
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>.
41bdb6e2
AJ
17
18 As a special exception, if you link the code in this file with
19 files compiled with a GNU compiler to produce an executable,
20 that does not cause the resulting executable to be covered by
21 the GNU Lesser General Public License. This exception does not
22 however invalidate any other reasons why the executable file
23 might be covered by the GNU Lesser General Public License.
24 This exception applies to code released by its copyright holders
25 in files containing the exception. */
96aa2d94
RM
26
27#include "libioP.h"
96aa2d94 28#include <stdlib.h>
5f0704b6
FW
29#include "../iconv/gconv_int.h"
30#include <shlib-compat.h>
96aa2d94
RM
31
32int
9964a145 33_IO_new_fclose (FILE *fp)
96aa2d94
RM
34{
35 int status;
36
6bc31da0
UD
37 CHECK_FILE(fp, EOF);
38
16710d58 39#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
c7f7281e
UD
40 /* We desperately try to help programs which are using streams in a
41 strange way and mix old and new functions. Detect old streams
42 here. */
bbdef797 43 if (_IO_vtable_offset (fp) != 0)
c7f7281e 44 return _IO_old_fclose (fp);
f1778711 45#endif
c7f7281e 46
beafb752 47 /* First unlink the stream. */
df6c012b 48 if (fp->_flags & _IO_IS_FILEBUF)
d18ea0c5 49 _IO_un_link ((struct _IO_FILE_plus *) fp);
beafb752 50
0261d33f 51 _IO_acquire_lock (fp);
df6c012b 52 if (fp->_flags & _IO_IS_FILEBUF)
d18ea0c5 53 status = _IO_file_close_it (fp);
96aa2d94 54 else
6bc31da0 55 status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
a334319f 56 _IO_release_lock (fp);
407a5515 57 _IO_FINISH (fp);
4e2e9999
UD
58 if (fp->_mode > 0)
59 {
4e2e9999
UD
60 /* This stream has a wide orientation. This means we have to free
61 the conversion functions. */
cd8b7ff9 62 struct _IO_codecvt *cc = fp->_codecvt;
4e2e9999 63
9e26f129 64 __libc_lock_lock (__gconv_lock);
129d706d
UD
65 __gconv_release_step (cc->__cd_in.__cd.__steps);
66 __gconv_release_step (cc->__cd_out.__cd.__steps);
9e26f129 67 __libc_lock_unlock (__gconv_lock);
77fe0b9c
UD
68 }
69 else
70 {
71 if (_IO_have_backup (fp))
d18ea0c5 72 _IO_free_backup_area (fp);
4e2e9999 73 }
a5406364 74 _IO_deallocate_file (fp);
96aa2d94
RM
75 return status;
76}
77
0bf98029 78versioned_symbol (libc, _IO_new_fclose, _IO_fclose, GLIBC_2_1);
6973fc01 79strong_alias (_IO_new_fclose, __new_fclose)
0bf98029 80versioned_symbol (libc, __new_fclose, fclose, GLIBC_2_1);