Many/most OSStatus values on iPhone are 4-character displayable values jammed into the 4-byte int. In order to make the values displayable in a hex dump on a little-endian system, the bytes are in reverse order in memory, such that simply copying them to a buffer with memcpy and tagging a null on the end doesn’t produce the desired result.
Does anyone have a clever way to swap the bytes around and get them into a character string in a relatively small number of (source code) keystrokes?
Wanting to minimize the amount of coding required (since this is diagnostic/debug code that needs to be kept simple) I opted for a C function that returns an NSString:
This allows the function to be used directly in an NSLog parameter list, eg, without the need to declare any temps.
Probably could tighten it up by using one of the swab variants, but that level of optimization isn’t necessary.