]> sourceware.org Git - glibc.git/blame - elf/dl-misc.c
Update.
[glibc.git] / elf / dl-misc.c
CommitLineData
0501d603 1/* Miscellaneous support functions for dynamic linker
49891c10 2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
9498096c
UD
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
0501d603
UD
20#include <assert.h>
21#include <fcntl.h>
9498096c
UD
22#include <unistd.h>
23#include <stdarg.h>
24#include <string.h>
8193034b 25#include <unistd.h>
0501d603
UD
26#include <sys/mman.h>
27#include <sys/stat.h>
8193034b 28#include <stdio-common/_itoa.h>
0501d603
UD
29
30#ifndef MAP_ANON
31/* This is the only dl-sysdep.c function that is actually needed at run-time
32 by _dl_map_object. */
33
34int
35_dl_sysdep_open_zero_fill (void)
36{
37 return __open ("/dev/zero", O_RDONLY);
38}
39#endif
40
41/* Read the whole contents of FILE into new mmap'd space with given
42 protections. *SIZEP gets the size of the file. */
43
44void *
45_dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
46{
47 void *result;
48 struct stat st;
49 int fd = __open (file, O_RDONLY);
50 if (fd < 0)
51 return NULL;
49891c10
UD
52 if (__fxstat (_STAT_VER, fd, &st) < 0
53 /* No need to map the file if it is empty. */
54 || st.st_size == 0)
0501d603
UD
55 result = NULL;
56 else
57 {
58 /* Map a copy of the file contents. */
59 result = __mmap (0, st.st_size, prot,
60#ifdef MAP_COPY
61 MAP_COPY
62#else
63 MAP_PRIVATE
64#endif
65#ifdef MAP_FILE
66 | MAP_FILE
67#endif
68 , fd, 0);
0413b54c 69 if (result == MAP_FAILED)
0501d603
UD
70 result = NULL;
71 else
72 *sizep = st.st_size;
73 }
74 __close (fd);
75 return result;
76}
9498096c
UD
77
78
7dea968e
UD
79/* Descriptor to write debug messages to. */
80int _dl_debug_fd;
9498096c
UD
81
82
83void
7dea968e 84_dl_sysdep_output (int fd, const char *msg, ...)
9498096c
UD
85{
86 va_list ap;
87
88 va_start (ap, msg);
89 do
90 {
91 size_t len = strlen (msg);
7dea968e 92 __write (fd, msg, len);
9498096c 93 msg = va_arg (ap, const char *);
8193034b
UD
94 }
95 while (msg != NULL);
96 va_end (ap);
97}
98
99
100void
101_dl_debug_message (int new_line, const char *msg, ...)
102{
103 /* We print the strings we get passed one after the other but start all
104 lines using the current PID. */
105 static int pid;
106 va_list ap;
107
108 if (pid == 0)
109 pid = getpid ();
110
111 va_start (ap, msg);
112 do
113 if (msg[0] == '\0')
114 /* Get the next argument. */
115 msg = va_arg (ap, const char *);
116 else
117 {
118 const char *endp;
119
120 /* We actually will print something in this line. So print the
121 PID now if needed. */
122 if (new_line)
123 {
124 char buf[7] = "00000:\t";
125 __write (_dl_debug_fd, _itoa_word (pid, &buf[5], 10, 0), 7);
126 new_line = 0;
127 }
128
129 endp = strchr (msg, '\n');
130 if (endp == NULL)
131 {
132 __write (_dl_debug_fd, msg, strlen (msg));
133 msg = va_arg (ap, const char *);
134 }
135 else
136 {
137 __write (_dl_debug_fd, msg, endp - msg + 1);
138 msg = endp + 1;
139 new_line = 1;
140 }
141 }
142 while (msg != NULL);
9498096c
UD
143 va_end (ap);
144}
This page took 0.050134 seconds and 5 git commands to generate.