Back to index

glibc  2.9
Defines | Functions
iofclose.c File Reference
#include "libioP.h"

Go to the source code of this file.

Defines

#define SHLIB_COMPAT(a, b, c)   0
#define _IO_new_fclose   fclose

Functions

int _IO_new_fclose (_IO_FILE *fp)

Define Documentation

#define _IO_new_fclose   fclose

Definition at line 37 of file iofclose.c.

#define SHLIB_COMPAT (   a,
  b,
  c 
)    0

Definition at line 36 of file iofclose.c.


Function Documentation

Definition at line 41 of file iofclose.c.

{
  int status;

  CHECK_FILE(fp, EOF);

#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  /* We desperately try to help programs which are using streams in a
     strange way and mix old and new functions.  Detect old streams
     here.  */
  if (_IO_vtable_offset (fp) != 0)
    return _IO_old_fclose (fp);
#endif

  /* First unlink the stream.  */
  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
    INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);

  _IO_acquire_lock (fp);
  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
    status = INTUSE(_IO_file_close_it) (fp);
  else
    status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
  _IO_release_lock (fp);
  _IO_FINISH (fp);
  if (fp->_mode > 0)
    {
#if _LIBC
      /* This stream has a wide orientation.  This means we have to free
        the conversion functions.  */
      struct _IO_codecvt *cc = fp->_codecvt;

      __libc_lock_lock (__gconv_lock);
      __gconv_release_step (cc->__cd_in.__cd.__steps);
      __gconv_release_step (cc->__cd_out.__cd.__steps);
      __libc_lock_unlock (__gconv_lock);
#endif
    }
  else
    {
      if (_IO_have_backup (fp))
       INTUSE(_IO_free_backup_area) (fp);
    }
  if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
    {
      fp->_IO_file_flags = 0;
      free(fp);
    }

  return status;
}

Here is the call graph for this function: