]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_transform/lib/c++utils.cpp
2 #include "SecCFRelease.h"
6 std::string
StringFromCFString(CFStringRef theString
)
8 CFIndex maxLength
= CFStringGetMaximumSizeForEncoding(CFStringGetLength(theString
), 0);
10 if (maxLength
<= 0) // roll over? just plain bad?
15 // leave room for NULL termination
18 char* buffer
= new char[maxLength
];
20 if (buffer
== NULL
) // out of memory? Naughty, naughty...
25 CFStringGetCString(theString
, buffer
, maxLength
, 0);
27 string
result(buffer
);
34 CFStringRef
CFStringFromString(std::string theString
)
36 return CFStringCreateWithCString(NULL
, theString
.c_str(), 0);
41 CFTypeRefHolder::~CFTypeRefHolder()
45 CFReleaseNull(mTypeRef
);
51 void CFTypeRefHolder::Set(CFTypeRef typeRef
)
55 CFReleaseNull(mTypeRef
);