Use most recent localedata from glibc-2.0.91.
[platform/upstream/glibc.git] / elf / dl-misc.c
1 /* Miscellaneous support functions for dynamic linker
2    Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
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    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 #include <assert.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <sys/mman.h>
26 #include <sys/stat.h>
27
28 #ifndef MAP_ANON
29 /* This is the only dl-sysdep.c function that is actually needed at run-time
30    by _dl_map_object.  */
31
32 int
33 _dl_sysdep_open_zero_fill (void)
34 {
35   return __open ("/dev/zero", O_RDONLY);
36 }
37 #endif
38
39 /* Read the whole contents of FILE into new mmap'd space with given
40    protections.  *SIZEP gets the size of the file.  */
41
42 void *
43 _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
44 {
45   void *result;
46   struct stat st;
47   int fd = __open (file, O_RDONLY);
48   if (fd < 0)
49     return NULL;
50   if (__fxstat (_STAT_VER, fd, &st) < 0
51       /* No need to map the file if it is empty.  */
52       || st.st_size == 0)
53     result = NULL;
54   else
55     {
56       /* Map a copy of the file contents.  */
57       result = __mmap (0, st.st_size, prot,
58 #ifdef MAP_COPY
59                        MAP_COPY
60 #else
61                        MAP_PRIVATE
62 #endif
63 #ifdef MAP_FILE
64                        | MAP_FILE
65 #endif
66                        , fd, 0);
67       if (result == MAP_FAILED)
68         result = NULL;
69       else
70         *sizep = st.st_size;
71     }
72   __close (fd);
73   return result;
74 }
75
76
77 void
78 _dl_sysdep_fatal (const char *msg, ...)
79 {
80   va_list ap;
81
82   va_start (ap, msg);
83   do
84     {
85       size_t len = strlen (msg);
86       __write (STDERR_FILENO, msg, len);
87       msg = va_arg (ap, const char *);
88     } while (msg);
89   va_end (ap);
90
91   _exit (127);
92 }
93
94
95 void
96 _dl_sysdep_error (const char *msg, ...)
97 {
98   va_list ap;
99
100   va_start (ap, msg);
101   do
102     {
103       size_t len = strlen (msg);
104       __write (STDERR_FILENO, msg, len);
105       msg = va_arg (ap, const char *);
106     } while (msg);
107   va_end (ap);
108 }
109
110
111 void
112 _dl_sysdep_message (const char *msg, ...)
113 {
114   va_list ap;
115
116   va_start (ap, msg);
117   do
118     {
119       size_t len = strlen (msg);
120       __write (STDOUT_FILENO, msg, len);
121       msg = va_arg (ap, const char *);
122     } while (msg);
123   va_end (ap);
124 }