Created
July 27, 2015 16:29
-
-
Save perfaram/057eb5b69cfe8134f6b2 to your computer and use it in GitHub Desktop.
Function that extracts human-readable information from OSStatus codes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//shamelessy taken from : https://github.com/Xcode-Snippets/Objective-C/blob/master/checkerror.m | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment