forked from koke/Xcode-Snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckerror.m
More file actions
26 lines (23 loc) · 789 Bytes
/
checkerror.m
File metadata and controls
26 lines (23 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// CheckError
// Function that extracts human-readable information from OSStatus codes.
//
// IDECodeSnippetCompletionScopes: [All]
// IDECodeSnippetIdentifier: A45C6E59-A7E9-4D18-80A9-F1AC24A699A7
// IDECodeSnippetLanguage: Xcode.SourceCodeLanguage.Objective-C
// IDECodeSnippetUserSnippet: 1
// IDECodeSnippetVersion: 2
static void CheckError(OSStatus error, const char *operation) {
if (error == noErr) {
return;
}
char str[20];
*(UInt32 *) (str + 1) = CFSwapInt32HostToBig(error);
if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
str[0] = str[5] = '\'';
str[6] = '\0';
} else {
sprintf(str, "%d", (int)error);
}
fprintf(stderr, "[Error] %s (%s)\n", operation, str);
exit(1);
}