NSLocalizedString can set errno
Tuesday 10 July 2007 - Filed under mac + programming
This is a short one, but it might help someone with debugging someday.
A while back, we had some code that was checking errno, then using the NSLocalizedString macro to get a localized error message, but it checked errno again later. Only the app isn’t localized yet. There’s no Localizable.strings file, so when NSBundle -localizedStringForKey gets called, even though it fails gracefully, it still ends up setting errno to “ENOENT”, or “file not found”.
So the lesson is – in case you’re seeing weird behavior where errno is changing after you check it, make sure you’re not using any system calls that might set it.
2007-07-10 » mike
10 July 2007 @ 10:42 am
Perhaps a better lesson: Always assume errno will be clobbered within a function call or macro.
10 July 2007 @ 10:45 am
Chris: agreed.