]> sourceware.org Git - glibc.git/blob - sysdeps/mach/hurd/mips/dl-machine.c
Update to LGPL v2.1.
[glibc.git] / sysdeps / mach / hurd / mips / dl-machine.c
1 /* Operating system support for run-time dynamic linker. MIPS specific
2 stuffs on Hurd.
3 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #include <hurd.h>
22 #include <link.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <stdlib.h>
26 #include <sys/mman.h>
27 #include <assert.h>
28 #include <sysdep.h>
29 #include <mach/mig_support.h>
30 #include "../stdio-common/_itoa.h"
31 #include <stdarg.h>
32 #include <ctype.h>
33 #include <sys/stat.h>
34 #include <libintl.h>
35
36 void weak_function
37 abort (void)
38 {
39 _exit (127);
40 }
41
42
43 #include <string.h>
44 #include <mach/error.h>
45 #include <errorlib.h>
46
47 #undef _
48 #define _(x) x
49
50 /* Return a string describing the errno code in ERRNUM. */
51 char * weak_function
52 _strerror_internal (int errnum, char *buf, size_t buflen)
53 {
54 int system;
55 int sub;
56 int code;
57 const struct error_system *es;
58 extern void __mach_error_map_compat (int *);
59
60 __mach_error_map_compat (&errnum);
61
62 system = err_get_system (errnum);
63 sub = err_get_sub (errnum);
64 code = err_get_code (errnum);
65
66 if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
67 {
68 const char *unk = _("Error in unknown error system: ");
69 const size_t unklen = strlen (unk);
70 char *p = buf + buflen;
71 *--p = '\0';
72 p = _itoa (errnum, p, 16, 1);
73 return memcpy (p - unklen, unk, unklen);
74 }
75
76 es = &__mach_error_systems[system];
77
78 if (sub >= es->max_sub)
79 return (char *) es->bad_sub;
80
81 if (code >= es->subsystem[sub].max_code)
82 {
83 const char *unk = _("Unknown error ");
84 const size_t unklen = strlen (unk);
85 char *p = buf + buflen;
86 size_t len = strlen (es->subsystem[sub].subsys_name);
87 *--p = '\0';
88 p = _itoa (errnum, p, 16, 1);
89 *p-- = ' ';
90 p = memcpy (p - len, es->subsystem[sub].subsys_name, len);
91 return memcpy (p - unklen, unk, unklen);
92 }
93
94 return (char *) _(es->subsystem[sub].codes[code]);
95 }
96
97 /* Read the whole contents of FILE into new mmap'd space with given
98 protections. The size of the file is returned in SIZE. */
99 void *
100 _dl_sysdep_read_whole_file (const char *file, size_t *size, int prot)
101 {
102 struct stat stat;
103 mach_port_t memobj_rd;
104 void *contents;
105 error_t err;
106
107 memobj_rd = __open (file, O_RDONLY, 0);
108 if (memobj_rd)
109 {
110 err = __io_stat ((file_t) memobj_rd, &stat);
111 if (err)
112 {
113 __hurd_fail (err);
114 contents = 0;
115 }
116 else
117 {
118 /* Map a copy of the file contents. */
119 contents = __mmap (0, stat.st_size, prot, MAP_COPY, memobj_rd, 0);
120 if (contents == (void *)-1)
121 contents = 0;
122 else
123 *size = stat.st_size;
124 }
125
126 __mach_port_deallocate (__mach_task_self (), memobj_rd);
127 }
128 else
129 contents = 0;
130
131 return contents;
132 }
This page took 0.04741 seconds and 6 git commands to generate.