]>
git.saurik.com Git - apple/security.git/blob - libsecurity_utilities/lib/errors.cpp
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <security_utilities/errors.h>
29 #include <security_utilities/debugging.h>
35 // From cssmapple.h - layering break
36 // Where should this go?
38 #define errSecErrnoBase 100000
39 #define errSecErrnoLimit 100255
42 // The base of the exception hierarchy.
43 // Note that the debug output here depends on a particular
44 // implementation feature of gcc; to wit, that the exception object
45 // is created and then copied (at least once) via its copy constructor.
46 // If your compiler does not invoke the copy constructor, you won't get
47 // debug output, but nothing worse should happen.
49 CommonError::CommonError()
55 // We strongly encourage catching all exceptions by const reference, so the copy
56 // constructor of our exceptions should never be called.
57 // We trace a copy to help catch violations of this rule.
59 CommonError::CommonError(const CommonError
&source
)
61 SECURITY_EXCEPTION_COPY(this, &source
);
64 CommonError::~CommonError() throw ()
66 SECURITY_EXCEPTION_HANDLED(this);
71 // UnixError exceptions
73 UnixError::UnixError() : error(errno
)
75 SECURITY_EXCEPTION_THROW_UNIX(this, errno
);
78 UnixError::UnixError(int err
) : error(err
)
80 SECURITY_EXCEPTION_THROW_UNIX(this, err
);
83 const char *UnixError::what() const throw ()
84 { return "UNIX error exception"; }
87 OSStatus
UnixError::osStatus() const
89 return error
+ errSecErrnoBase
;
92 int UnixError::unixError() const
95 void UnixError::throwMe(int err
) { throw UnixError(err
); }
97 // @@@ This is a hack for the Network protocol state machine
98 UnixError
UnixError::make(int err
) { return UnixError(err
); }
102 // MacOSError exceptions
104 MacOSError::MacOSError(int err
) : error(err
)
106 SECURITY_EXCEPTION_THROW_OSSTATUS(this, err
);
109 const char *MacOSError::what() const throw ()
110 { return "MacOS error"; }
112 OSStatus
MacOSError::osStatus() const
115 int MacOSError::unixError() const
117 // embedded UNIX errno values are returned verbatim
118 if (error
>= errSecErrnoBase
&& error
<= errSecErrnoLimit
)
119 return error
- errSecErrnoBase
;
123 // cannot map this to errno space
128 void MacOSError::throwMe(int error
)
129 { throw MacOSError(error
); }
133 // CFError exceptions
137 SECURITY_EXCEPTION_THROW_CF(this);
140 const char *CFError::what() const throw ()
141 { return "CoreFoundation error"; }
143 // can't get this from CarbonCore/MacErrors, but it's too good to pass up
145 coreFoundationUnknownErr
= -4960
148 OSStatus
CFError::osStatus() const
149 { return coreFoundationUnknownErr
; }
151 int CFError::unixError() const
153 return EFAULT
; // nothing really matches
156 void CFError::throwMe()