1 /* Operating system support for run-time dynamic linker. MIPS specific
3 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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.
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.
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
29 #include <mach/mig_support.h>
30 #include "../stdio-common/_itoa.h"
44 #include <mach/error.h>
50 /* Return a string describing the errno code in ERRNUM. */
52 _strerror_internal (int errnum
, char *buf
, size_t buflen
)
57 const struct error_system
*es
;
58 extern void __mach_error_map_compat (int *);
60 __mach_error_map_compat (&errnum
);
62 system
= err_get_system (errnum
);
63 sub
= err_get_sub (errnum
);
64 code
= err_get_code (errnum
);
66 if (system
> err_max_system
|| ! __mach_error_systems
[system
].bad_sub
)
68 const char *unk
= _("Error in unknown error system: ");
69 const size_t unklen
= strlen (unk
);
70 char *p
= buf
+ buflen
;
72 p
= _itoa (errnum
, p
, 16, 1);
73 return memcpy (p
- unklen
, unk
, unklen
);
76 es
= &__mach_error_systems
[system
];
78 if (sub
>= es
->max_sub
)
79 return (char *) es
->bad_sub
;
81 if (code
>= es
->subsystem
[sub
].max_code
)
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
);
88 p
= _itoa (errnum
, p
, 16, 1);
90 p
= memcpy (p
- len
, es
->subsystem
[sub
].subsys_name
, len
);
91 return memcpy (p
- unklen
, unk
, unklen
);
94 return (char *) _(es
->subsystem
[sub
].codes
[code
]);
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. */
100 _dl_sysdep_read_whole_file (const char *file
, size_t *size
, int prot
)
103 mach_port_t memobj_rd
;
107 memobj_rd
= __open (file
, O_RDONLY
, 0);
110 err
= __io_stat ((file_t
) memobj_rd
, &stat
);
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)
123 *size
= stat
.st_size
;
126 __mach_port_deallocate (__mach_task_self (), memobj_rd
);