StikJIT/Sources/IdeviceFFI.swift
Stephen 99f2db2161 Initial commit
Initial commit
2026-06-23 12:17:03 -04:00

21 lines
788 B
Swift

import Foundation
@_implementationOnly import idevice
enum IdeviceFFI {
static func consume(_ pointer: UnsafeMutablePointer<IdeviceFfiError>?,
fallback: String) -> StikJITError {
guard let pointer else { return .device(code: -1, subCode: 0, message: fallback) }
let error = StikJITError.device(
code: pointer.pointee.code,
subCode: pointer.pointee.sub_code,
message: pointer.pointee.message.map { String(cString: $0) } ?? fallback)
idevice_error_free(pointer)
return error
}
static func check(_ fallback: String,
_ call: () -> UnsafeMutablePointer<IdeviceFfiError>?) throws {
if let error = call() { throw consume(error, fallback: fallback) }
}
}