]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/_strerror.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / mach / _strerror.c
CommitLineData
6d7e8eda 1/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
478b92f0 2 This file is part of the GNU C Library.
28f540f4 3
478b92f0 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
28f540f4 8
478b92f0
UD
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4 17
08d2024b 18#include <string.h>
6818bcae 19#include <libintl.h>
28f540f4
RM
20#include <stdio.h>
21#include <string.h>
22#include <mach/error.h>
421f82e5 23#include <errorlib.h>
6ed0492f 24
28f540f4
RM
25/* Return a string describing the errno code in ERRNUM. */
26char *
310b3460 27__strerror_r (int errnum, char *buf, size_t buflen)
28f540f4 28{
86d2c878 29 int system;
28f540f4
RM
30 int sub;
31 int code;
32 const struct error_system *es;
33 extern void __mach_error_map_compat (int *);
34
35 __mach_error_map_compat (&errnum);
36
37 system = err_get_system (errnum);
38 sub = err_get_sub (errnum);
39 code = err_get_code (errnum);
40
421f82e5 41 if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
28f540f4 42 {
03ad444e 43 __snprintf (buf, buflen, "%s%X", _("Error in unknown error system: "),
08d2024b 44 errnum);
af69217f 45 return buf;
28f540f4
RM
46 }
47
48 es = &__mach_error_systems[system];
49
50 if (sub >= es->max_sub)
51 return (char *) es->bad_sub;
52
53 if (code >= es->subsystem[sub].max_code)
54 {
08d2024b
AZ
55 __snprintf (buf, buflen, "%s%s %d", _("Unknown error "),
56 es->subsystem[sub].subsys_name, errnum);
af69217f 57 return buf;
28f540f4
RM
58 }
59
b3a59f40 60 return (char *) _(es->subsystem[sub].codes[code]);
28f540f4 61}
7a9ce79a 62libc_hidden_def (__strerror_r)
310b3460 63weak_alias (__strerror_r, strerror_r)