X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/822b670c6f91d089ccb51b77e24b6ac80406b337..7e6b461318c8a779d91381531435a68ee4e8b6ed:/OSX/libsecurity_utilities/lib/cfutilities.h?ds=sidebyside diff --git a/OSX/libsecurity_utilities/lib/cfutilities.h b/OSX/libsecurity_utilities/lib/cfutilities.h index ad4fc80d..888de1c0 100644 --- a/OSX/libsecurity_utilities/lib/cfutilities.h +++ b/OSX/libsecurity_utilities/lib/cfutilities.h @@ -342,8 +342,8 @@ inline CFStringRef makeCFString(CFDataRef data, CFStringEncoding encoding = kCFS // // Create CFURL objects from various sources // -CFURLRef makeCFURL(const char *s, bool isDirectory = false, CFURLRef base = NULL); -CFURLRef makeCFURL(CFStringRef s, bool isDirectory = false, CFURLRef base = NULL); +CFURLRef CF_RETURNS_RETAINED makeCFURL(const char *s, bool isDirectory = false, CFURLRef base = NULL); +CFURLRef CF_RETURNS_RETAINED makeCFURL(CFStringRef s, bool isDirectory = false, CFURLRef base = NULL); inline CFURLRef makeCFURL(const string &s, bool isDirectory = false, CFURLRef base = NULL) { @@ -409,10 +409,15 @@ inline CFDataRef makeCFData(const void *data, size_t size) { return CFDataCreate(NULL, (const UInt8 *)data, size); } - + inline CFDataRef makeCFData(CFDictionaryRef dictionary) { - return CFPropertyListCreateXMLData(NULL, dictionary); + return CFPropertyListCreateData(NULL, dictionary, kCFPropertyListXMLFormat_v1_0, 0, NULL); +} + +inline CFDataRef makeCFData(CFArrayRef array) +{ + return CFPropertyListCreateData(NULL, array, kCFPropertyListXMLFormat_v1_0, 0, NULL); } template @@ -470,10 +475,10 @@ private: // // Make CFDictionaries from stuff // -CFDictionaryRef makeCFDictionary(unsigned count, ...); // key/value pairs -CFMutableDictionaryRef makeCFMutableDictionary(); // empty -CFMutableDictionaryRef makeCFMutableDictionary(unsigned count, ...); // (count) key/value pairs -CFMutableDictionaryRef makeCFMutableDictionary(CFDictionaryRef dict); // copy of dictionary +CFDictionaryRef makeCFDictionary(unsigned count, ...) CF_RETURNS_RETAINED; // key/value pairs +CFMutableDictionaryRef makeCFMutableDictionary() CF_RETURNS_RETAINED; // empty +CFMutableDictionaryRef makeCFMutableDictionary(unsigned count, ...) CF_RETURNS_RETAINED; // (count) key/value pairs +CFMutableDictionaryRef makeCFMutableDictionary(CFDictionaryRef dict) CF_RETURNS_RETAINED; // copy of dictionary CFDictionaryRef makeCFDictionaryFrom(CFDataRef data) CF_RETURNS_RETAINED;// interpret plist form CFDictionaryRef makeCFDictionaryFrom(const void *data, size_t length) CF_RETURNS_RETAINED; // ditto @@ -550,12 +555,28 @@ void cfDictionaryApplyBlock(CFDictionaryRef source, CFDictionaryApplierBlock blo // // CFURLAccess wrappers for specific purposes +// cfLoadFile family will use mmap(2) when appropriate +// cfReadFile will read the data into memory +// cfMapFile will mmap(2) the file // -CFDataRef cfLoadFile(CFURLRef url); -CFDataRef cfLoadFile(int fd, size_t bytes); -inline CFDataRef cfLoadFile(CFStringRef path) { return cfLoadFile(CFTempURL(path)); } -inline CFDataRef cfLoadFile(const std::string &path) { return cfLoadFile(CFTempURL(path)); } -inline CFDataRef cfLoadFile(const char *path) { return cfLoadFile(CFTempURL(path)); } +CFDataRef CF_RETURNS_RETAINED cfLoadFile(CFURLRef url); +CFDataRef CF_RETURNS_RETAINED cfLoadFile(int fd, size_t bytes); +inline CFDataRef CF_RETURNS_RETAINED cfLoadFile(CFStringRef path) { return cfLoadFile(CFTempURL(path)); } +inline CFDataRef CF_RETURNS_RETAINED cfLoadFile(const std::string &path) { return cfLoadFile(CFTempURL(path)); } +inline CFDataRef CF_RETURNS_RETAINED cfLoadFile(const char *path) { return cfLoadFile(CFTempURL(path)); } + + +CFDataRef cfReadFile(CFURLRef url) CF_RETURNS_RETAINED; +CFDataRef cfReadFile(int fd, size_t bytes) CF_RETURNS_RETAINED; +inline CFDataRef cfReadFile(CFStringRef path) { return cfReadFile(CFTempURL(path)); } +inline CFDataRef cfReadFile(const std::string &path) { return cfReadFile(CFTempURL(path)); } +inline CFDataRef cfReadFile(const char *path) { return cfReadFile(CFTempURL(path)); } + +CFDataRef cfMapFile(CFURLRef url) CF_RETURNS_RETAINED; +CFDataRef cfMapFile(int fd, size_t bytes) CF_RETURNS_RETAINED; +inline CFDataRef cfMapFile(CFStringRef path) { return cfMapFile(CFTempURL(path)); } +inline CFDataRef cfMapFile(const std::string &path) { return cfMapFile(CFTempURL(path)); } +inline CFDataRef cfMapFile(const char *path) { return cfMapFile(CFTempURL(path)); } // @@ -618,7 +639,7 @@ CFToVector::CFToVector(CFArrayRef arrayRef) // Make CFArrays from stuff. // template -inline CFArrayRef makeCFArray(Generator &generate, Iterator first, Iterator last) +inline CFArrayRef CF_RETURNS_RETAINED makeCFArrayFrom(const Generator &generate, Iterator first, Iterator last) { // how many elements? size_t size = distance(first, last); @@ -632,9 +653,9 @@ inline CFArrayRef makeCFArray(Generator &generate, Iterator first, Iterator last } template -inline CFArrayRef makeCFArray(Generator &generate, const Container &container) +inline CFArrayRef makeCFArrayFrom(const Generator &generate, const Container &container) { - return makeCFArray(generate, container.begin(), container.end()); + return makeCFArrayFrom(generate, container.begin(), container.end()); } CFArrayRef makeCFArray(CFIndex count, ...) CF_RETURNS_RETAINED;