]> sourceware.org Git - glibc.git/blob - elf/dl-misc.c
90288525f4b7cc5ef81c02648f336cd5521fbf46
[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 /* Descriptor to write debug messages to. */
78 int _dl_debug_fd;
79
80
81 void
82 _dl_sysdep_output (int fd, const char *msg, ...)
83 {
84 va_list ap;
85
86 va_start (ap, msg);
87 do
88 {
89 size_t len = strlen (msg);
90 __write (fd, msg, len);
91 msg = va_arg (ap, const char *);
92 } while (msg);
93 va_end (ap);
94 }
This page took 0.039691 seconds and 4 git commands to generate.