2014-02-26 22:43:31 -08:00
|
|
|
#pragma once
|
|
|
|
|
2014-03-04 06:10:33 -08:00
|
|
|
#include <util/dstr.h>
|
|
|
|
|
2014-02-26 22:43:31 -08:00
|
|
|
static inline bool mac_success(OSStatus stat, const char *action)
|
|
|
|
{
|
|
|
|
if (stat != noErr) {
|
|
|
|
blog(LOG_WARNING, "%s failed: %d", action, (int)stat);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cf_to_cstr(CFStringRef ref, char *buf, size_t size)
|
|
|
|
{
|
2014-03-03 01:56:54 -08:00
|
|
|
if (!ref) return false;
|
2014-02-26 22:43:31 -08:00
|
|
|
return (bool)CFStringGetCString(ref, buf, size, kCFStringEncodingUTF8);
|
|
|
|
}
|
2014-03-03 01:56:54 -08:00
|
|
|
|
|
|
|
static inline bool cf_to_dstr(CFStringRef ref, struct dstr *str)
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
if (!ref) return false;
|
|
|
|
|
|
|
|
size = (size_t)CFStringGetLength(ref);
|
|
|
|
dstr_resize(str, size);
|
|
|
|
|
|
|
|
return (bool)CFStringGetCString(ref, str->array, size+1,
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
}
|