Back to index

glibc  2.9
freopen64.c
Go to the documentation of this file.
00001 /* Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002, 2003, 2008
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.
00019 
00020    As a special exception, if you link the code in this file with
00021    files compiled with a GNU compiler to produce an executable,
00022    that does not cause the resulting executable to be covered by
00023    the GNU Lesser General Public License.  This exception does not
00024    however invalidate any other reasons why the executable file
00025    might be covered by the GNU Lesser General Public License.
00026    This exception applies to code released by its copyright holders
00027    in files containing the exception.  */
00028 
00029 #include "libioP.h"
00030 #include "stdio.h"
00031 #include <stdlib.h>
00032 
00033 #include <fd_to_filename.h>
00034 
00035 FILE *
00036 freopen64 (filename, mode, fp)
00037      const char* filename;
00038      const char* mode;
00039      FILE *fp;
00040 {
00041 #ifdef _G_OPEN64
00042   FILE *result;
00043   int fd = -1;
00044   CHECK_FILE (fp, NULL);
00045   if (!(fp->_flags & _IO_IS_FILEBUF))
00046     return NULL;
00047   _IO_acquire_lock (fp);
00048   if (filename == NULL && _IO_fileno (fp) >= 0)
00049     {
00050       fd = __dup (_IO_fileno (fp));
00051       if (fd != -1)
00052        filename = fd_to_filename (fd);
00053     }
00054   INTUSE(_IO_file_close_it) (fp);
00055   _IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps;
00056   if (_IO_vtable_offset (fp) == 0 && fp->_wide_data != NULL)
00057     fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
00058   result = INTUSE(_IO_file_fopen) (fp, filename, mode, 0);
00059   if (result != NULL)
00060     result = __fopen_maybe_mmap (result);
00061   if (result != NULL)
00062     /* unbound stream orientation */
00063     result->_mode = 0;
00064   if (fd != -1)
00065     {
00066       __close (fd);
00067       free ((char *) filename);
00068     }
00069   _IO_release_lock (fp);
00070   return result;
00071 #else
00072   __set_errno (ENOSYS);
00073   return NULL;
00074 #endif
00075 }