Back to index

glibc  2.9
oldiofclose.c
Go to the documentation of this file.
00001 /* Copyright (C) 1993,1995,1997-2002,2004,2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.
00018 
00019    As a special exception, if you link the code in this file with
00020    files compiled with a GNU compiler to produce an executable,
00021    that does not cause the resulting executable to be covered by
00022    the GNU Lesser General Public License.  This exception does not
00023    however invalidate any other reasons why the executable file
00024    might be covered by the GNU Lesser General Public License.
00025    This exception applies to code released by its copyright holders
00026    in files containing the exception.  */
00027 
00028 #include <shlib-compat.h>
00029 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
00030 
00031 #define _IO_USE_OLD_IO_FILE
00032 #include "libioP.h"
00033 #ifdef __STDC__
00034 #include <stdlib.h>
00035 #endif
00036 
00037 int
00038 attribute_compat_text_section
00039 _IO_old_fclose (fp)
00040      _IO_FILE *fp;
00041 {
00042   int status;
00043 
00044   CHECK_FILE(fp, EOF);
00045 
00046   /* We desperately try to help programs which are using streams in a
00047      strange way and mix old and new functions.  Detect new streams
00048      here.  */
00049   if (fp->_vtable_offset == 0)
00050     return _IO_new_fclose (fp);
00051 
00052   /* First unlink the stream.  */
00053   if (fp->_IO_file_flags & _IO_IS_FILEBUF)
00054     INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
00055 
00056   _IO_acquire_lock (fp);
00057   if (fp->_IO_file_flags & _IO_IS_FILEBUF)
00058     status = _IO_old_file_close_it (fp);
00059   else
00060     status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
00061   _IO_release_lock (fp);
00062   _IO_FINISH (fp);
00063   if (_IO_have_backup (fp))
00064     INTUSE(_IO_free_backup_area) (fp);
00065   if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
00066     {
00067       fp->_IO_file_flags = 0;
00068       free(fp);
00069     }
00070 
00071   return status;
00072 }
00073 
00074 strong_alias (_IO_old_fclose, __old_fclose)
00075 compat_symbol (libc, _IO_old_fclose, _IO_fclose, GLIBC_2_0);
00076 compat_symbol (libc, __old_fclose, fclose, GLIBC_2_0);
00077 
00078 #endif