开发者

Mapping IOKit IOReturn error code to String

开发者 https://www.devze.com 2023-01-19 17:19 出处:网络
When I get error 0x10, I want to 开发者_如何学Gobe able to make sense of that error code. Looking up IOReturn.h and mach/error.h is not particularly convenient. I was lost when I got 0x22 error code.

When I get error 0x10, I want to 开发者_如何学Gobe able to make sense of that error code. Looking up IOReturn.h and mach/error.h is not particularly convenient. I was lost when I got 0x22 error code. This is really silly question but is there a function like error2String which can map IOReturn error code to String that describes the error ?


You can use the mach_error_string standard foundation function to do this.

Eg. in Swift:

func krToString (_ kr: kern_return_t) -> String {
    if let cStr = mach_error_string(kr) {
        return String (cString: cStr)
    } else {
        return "Unknown kernel error \(kr)"
    }
}


Code running in the kernel can use IOService::stringFromReturn(...)

0

精彩评论

暂无评论...
验证码 换一张
取 消