core_foundation_sys/
error.rs

1// Copyright 2016 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use std::os::raw::c_void;
11
12use crate::base::{CFAllocatorRef, CFIndex, CFTypeID};
13use crate::dictionary::CFDictionaryRef;
14use crate::string::CFStringRef;
15
16#[repr(C)]
17pub struct __CFError(c_void);
18
19pub type CFErrorRef = *mut __CFError;
20pub type CFErrorDomain = CFStringRef;
21
22extern "C" {
23    /*
24     * CFError.h
25     */
26
27    /* Error domains */
28    pub static kCFErrorDomainPOSIX: CFStringRef;
29    pub static kCFErrorDomainOSStatus: CFStringRef;
30    pub static kCFErrorDomainMach: CFStringRef;
31    pub static kCFErrorDomainCocoa: CFStringRef;
32
33    /* Keys for the user info dictionary */
34    pub static kCFErrorLocalizedDescriptionKey: CFStringRef;
35    // pub static kCFErrorLocalizedFailureKey: CFStringRef; // macos(10.13)+
36    pub static kCFErrorLocalizedFailureReasonKey: CFStringRef;
37    pub static kCFErrorLocalizedRecoverySuggestionKey: CFStringRef;
38    pub static kCFErrorDescriptionKey: CFStringRef;
39    pub static kCFErrorUnderlyingErrorKey: CFStringRef;
40    pub static kCFErrorURLKey: CFStringRef;
41    pub static kCFErrorFilePathKey: CFStringRef;
42
43    /* Creating a CFError */
44    pub fn CFErrorCreate(
45        allocator: CFAllocatorRef,
46        domain: CFErrorDomain,
47        code: CFIndex,
48        userInfo: CFDictionaryRef,
49    ) -> CFErrorRef;
50    //pub fn CFErrorCreateWithUserInfoKeysAndValues
51
52    /* Getting Information About an Error */
53    pub fn CFErrorGetDomain(err: CFErrorRef) -> CFStringRef;
54    pub fn CFErrorGetCode(err: CFErrorRef) -> CFIndex;
55    pub fn CFErrorCopyUserInfo(err: CFErrorRef) -> CFDictionaryRef;
56    pub fn CFErrorCopyDescription(err: CFErrorRef) -> CFStringRef;
57    pub fn CFErrorCopyFailureReason(err: CFErrorRef) -> CFStringRef;
58    pub fn CFErrorCopyRecoverySuggestion(err: CFErrorRef) -> CFStringRef;
59
60    /* Getting the CFError Type ID */
61    pub fn CFErrorGetTypeID() -> CFTypeID;
62}