Give Hurd weak aliases for getsysstats get_* functions.
[glibc.git] / libio / iofopen.c
blob5051f7a7afcb017dd072ad7c84da62124be15508
1 /* Copyright (C) 1993,1997,1998,1999,2000,2002,2003
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA.
20 As a special exception, if you link the code in this file with
21 files compiled with a GNU compiler to produce an executable,
22 that does not cause the resulting executable to be covered by
23 the GNU Lesser General Public License. This exception does not
24 however invalidate any other reasons why the executable file
25 might be covered by the GNU Lesser General Public License.
26 This exception applies to code released by its copyright holders
27 in files containing the exception. */
29 #include "libioP.h"
30 #ifdef __STDC__
31 #include <stdlib.h>
32 #include <stddef.h>
33 #endif
34 #ifdef _LIBC
35 # include <shlib-compat.h>
36 #else
37 # define _IO_new_fopen fopen
38 #endif
40 _IO_FILE *
41 __fopen_maybe_mmap (fp)
42 _IO_FILE *fp;
44 #ifdef _G_HAVE_MMAP
45 if ((fp->_flags2 & _IO_FLAGS2_MMAP) && (fp->_flags & _IO_NO_WRITES))
47 /* Since this is read-only, we might be able to mmap the contents
48 directly. We delay the decision until the first read attempt by
49 giving it a jump table containing functions that choose mmap or
50 vanilla file operations and reset the jump table accordingly. */
52 if (fp->_mode <= 0)
53 _IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps_maybe_mmap;
54 else
55 _IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_wfile_jumps_maybe_mmap;
56 fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_maybe_mmap;
58 #endif
59 return fp;
63 _IO_FILE *
64 __fopen_internal (filename, mode, is32)
65 const char *filename;
66 const char *mode;
67 int is32;
69 struct locked_FILE
71 struct _IO_FILE_plus fp;
72 #ifdef _IO_MTSAFE_IO
73 _IO_lock_t lock;
74 #endif
75 struct _IO_wide_data wd;
76 } *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
78 if (new_f == NULL)
79 return NULL;
80 #ifdef _IO_MTSAFE_IO
81 new_f->fp.file._lock = &new_f->lock;
82 #endif
83 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
84 _IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd, &_IO_wfile_jumps);
85 #else
86 _IO_no_init (&new_f->fp.file, 1, 0, NULL, NULL);
87 #endif
88 _IO_JUMPS (&new_f->fp) = &_IO_file_jumps;
89 INTUSE(_IO_file_init) (&new_f->fp);
90 #if !_IO_UNIFIED_JUMPTABLES
91 new_f->fp.vtable = NULL;
92 #endif
93 if (INTUSE(_IO_file_fopen) ((_IO_FILE *) new_f, filename, mode, is32)
94 != NULL)
95 return __fopen_maybe_mmap (&new_f->fp.file);
97 INTUSE(_IO_un_link) (&new_f->fp);
98 free (new_f);
99 return NULL;
102 _IO_FILE *
103 _IO_new_fopen (filename, mode)
104 const char *filename;
105 const char *mode;
107 return __fopen_internal (filename, mode, 1);
110 #ifdef _LIBC
111 strong_alias (_IO_new_fopen, __new_fopen)
112 versioned_symbol (libc, _IO_new_fopen, _IO_fopen, GLIBC_2_1);
113 versioned_symbol (libc, __new_fopen, fopen, GLIBC_2_1);
114 #endif