]> git.saurik.com Git - apple/libc.git/blob - mach.subproj/mach_error_string.c
Libc-166.tar.gz
[apple/libc.git] / mach.subproj / mach_error_string.c
1 /*
2 * @OSF_COPYRIGHT@
3 */
4 /*
5 * Mach Operating System
6 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
7 * All Rights Reserved.
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
28 */
29
30 #include <mach/boolean.h>
31 #include <mach/error.h>
32 #include <mach/mach_error.h>
33 #include <mach/errorlib.h>
34 #include "externs.h"
35
36 static void do_compat(mach_error_t *);
37
38 static void
39 do_compat(mach_error_t *org_err)
40 {
41 mach_error_t err = *org_err;
42
43 /*
44 * map old error numbers to
45 * to new error sys & subsystem
46 */
47
48 if ((-200 < err) && (err <= -100))
49 err = -(err + 100) | IPC_SEND_MOD;
50 else if ((-300 < err) && (err <= -200))
51 err = -(err + 200) | IPC_RCV_MOD;
52 else if ((-400 < err) && (err <= -300))
53 err = -(err + 300) | MACH_IPC_MIG_MOD;
54 else if ((1000 <= err) && (err < 1100))
55 err = (err - 1000) | SERV_NETNAME_MOD;
56 else if ((1600 <= err) && (err < 1700))
57 err = (err - 1600) | SERV_ENV_MOD;
58 else if ((27600 <= err) && (err < 27700))
59 err = (err - 27600) | SERV_EXECD_MOD;
60
61 *org_err = err;
62 }
63
64 char *
65 mach_error_type(mach_error_t err)
66 {
67 int sub, system;
68
69 do_compat( &err );
70
71 sub = err_get_sub(err);
72 system = err_get_system(err);
73
74 if (system > err_max_system || sub >= errors[system].max_sub)
75 return((char *)"(?/?)");
76 return(errors[system].subsystem[sub].subsys_name);
77 }
78
79 boolean_t mach_error_full_diag = FALSE;
80
81 char *
82 mach_error_string_int(mach_error_t err, boolean_t *diag)
83 {
84 int sub, system, code;
85
86 do_compat( &err );
87
88 sub = err_get_sub(err);
89 system = err_get_system(err);
90 code = err_get_code(err);
91
92 *diag = TRUE;
93
94 if (system > err_max_system)
95 return((char *)"(?/?) unknown error system");
96 if (sub >= errors[system].max_sub)
97 return(errors[system].bad_sub);
98 if (code >= errors[system].subsystem[sub].max_code)
99 return ((char *)NO_SUCH_ERROR);
100
101 *diag = mach_error_full_diag;
102 return( errors[system].subsystem[sub].codes[code] );
103 }
104
105 char *
106 mach_error_string(mach_error_t err)
107 {
108 boolean_t diag;
109
110 return mach_error_string_int( err, &diag );
111
112 }