mac-helpers.h 632 B

1234567891011121314151617181920212223242526272829
  1. #pragma once
  2. static inline bool mac_success(OSStatus stat, const char *action)
  3. {
  4. if (stat != noErr) {
  5. blog(LOG_WARNING, "%s failed: %d", action, (int)stat);
  6. return false;
  7. }
  8. return true;
  9. }
  10. static inline bool cf_to_cstr(CFStringRef ref, char *buf, size_t size)
  11. {
  12. if (!ref) return false;
  13. return (bool)CFStringGetCString(ref, buf, size, kCFStringEncodingUTF8);
  14. }
  15. static inline bool cf_to_dstr(CFStringRef ref, struct dstr *str)
  16. {
  17. size_t size;
  18. if (!ref) return false;
  19. size = (size_t)CFStringGetLength(ref);
  20. dstr_resize(str, size);
  21. return (bool)CFStringGetCString(ref, str->array, size+1,
  22. kCFStringEncodingUTF8);
  23. }