1 /* Copyright (C) 1993,95,96,97,98,2000,2001,2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 As a special exception, if you link the code in this file with
20 files compiled with a GNU compiler to produce an executable,
21 that does not cause the resulting executable to be covered by
22 the GNU Lesser General Public License. This exception does not
23 however invalidate any other reasons why the executable file
24 might be covered by the GNU Lesser General Public License.
25 This exception applies to code released by its copyright holders
26 in files containing the exception. */
31 #include <shlib-compat.h>
34 freopen (filename
, mode
, fp
)
40 CHECK_FILE (fp
, NULL
);
41 if (!(fp
->_flags
& _IO_IS_FILEBUF
))
43 _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile
, fp
);
45 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
46 if (&_IO_stdin_used
== NULL
)
47 /* If the shared C library is used by the application binary which
48 was linked against the older version of libio, we just use the
49 older one even for internal use to avoid trouble since a pointer
50 to the old libio may be passed into shared C library and wind
52 result
= _IO_old_freopen (filename
, mode
, fp
);
55 result
= _IO_freopen (filename
, mode
, fp
);
57 /* unbound stream orientation */
60 _IO_cleanup_region_end (0);
65 #include <fd_to_filename.h>
68 freopen (filename
, mode
, fp
)
75 CHECK_FILE (fp
, NULL
);
76 if (!(fp
->_flags
& _IO_IS_FILEBUF
))
78 _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile
, fp
);
80 if (filename
== NULL
&& _IO_fileno (fp
) >= 0)
82 fd
= __dup (_IO_fileno (fp
));
84 filename
= fd_to_filename (fd
);
86 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
87 if (&_IO_stdin_used
== NULL
)
89 /* If the shared C library is used by the application binary which
90 was linked against the older version of libio, we just use the
91 older one even for internal use to avoid trouble since a pointer
92 to the old libio may be passed into shared C library and wind
94 _IO_old_file_close_it (fp
);
95 _IO_JUMPS ((struct _IO_FILE_plus
*) fp
) = &_IO_old_file_jumps
;
96 result
= _IO_old_file_fopen (fp
, filename
, mode
);
101 INTUSE(_IO_file_close_it
) (fp
);
102 _IO_JUMPS ((struct _IO_FILE_plus
*) fp
) = &INTUSE(_IO_file_jumps
);
103 // if (fp->_vtable_offset == 0 && fp->_wide_data != NULL)
104 // fp->_wide_data->_wide_vtable = &INTUSE(_IO_wfile_jumps);
105 result
= INTUSE(_IO_file_fopen
) (fp
, filename
, mode
, 1);
107 result
= __fopen_maybe_mmap (result
);
110 /* unbound stream orientation */
115 if (filename
!= NULL
)
116 free ((char *) filename
);
118 _IO_funlockfile (fp
);
119 _IO_cleanup_region_end (0);