michael-mccracken.net

NSLocalizedString can set errno

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.

Comments:
  1. Chris
    July 10th, 2007 | 10:42 am

    Perhaps a better lesson: Always assume errno will be clobbered within a function call or macro.

  2. July 10th, 2007 | 10:45 am

    Chris: agreed.

Leave a reply

Feed, Endorsements & other Links

my bookmarks

© 2005 - 2007 Michael McCracken.