const char * sys_runtime_dir(void) { if (_nix_runtime_dir[0] == 0x0) { #if defined(_IOS) CFURLRef url = CFCopyHomeDirectoryURL(); CFStringRef path = CFURLCopyPath(url); memset(_nix_tmp_buff, 0x0, PATH_MAX); CFStringGetCString(path, _nix_tmp_buff, PATH_MAX, kCFStringEncodingUTF8); CFRelease(path); CFRelease(url); snprintf(_nix_cache_dir, PATH_MAX, "%s/run", _nix_tmp_buff); #elif defined(__ANDROID__) #else snprintf(_nix_runtime_dir, PATH_MAX, "/var/run/%s", _miwa_sys_name); #endif if (sys_directory_exists(_nix_runtime_dir) < 0) sys_create_directory(_nix_runtime_dir); } return _nix_runtime_dir; }
static CFURLRef SecCopyHomeURL(void) { // This returns a CFURLRef so that it can be passed as the second parameter // to CFURLCreateCopyAppendingPathComponent CFURLRef homeURL = sCustomHomeURL; if (homeURL) { CFRetain(homeURL); } else { #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) // We would use CFCopyHomeDirectoryURL but it doesn't exist on MACOS. // This does the same. homeURL = CFCopyHomeDirectoryURLForUser(NULL); #else homeURL = CFCopyHomeDirectoryURL(); #endif } return homeURL; }
CF_EXPORT CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName) { #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD if (!uName) { uid_t euid; __CFGetUGIDs(&euid, NULL); struct passwd *upwd = getpwuid(euid ? euid : getuid()); return _CFCopyHomeDirURLForUser(upwd, true); } else { struct passwd *upwd = NULL; char buf[128], *user; SInt32 len = CFStringGetLength(uName), size = CFStringGetMaximumSizeForEncoding(len, kCFPlatformInterfaceStringEncoding); CFIndex usedSize; if (size < 127) { user = buf; } else { user = CFAllocatorAllocate(kCFAllocatorSystemDefault, size+1, 0); } if (CFStringGetBytes(uName, CFRangeMake(0, len), kCFPlatformInterfaceStringEncoding, 0, true, (uint8_t *)user, size, &usedSize) == len) { user[usedSize] = '\0'; upwd = getpwnam(user); } if (buf != user) { CFAllocatorDeallocate(kCFAllocatorSystemDefault, user); } return _CFCopyHomeDirURLForUser(upwd, false); } #elif DEPLOYMENT_TARGET_WINDOWS // This code can only get the directory for the current user CFStringRef userName = uName ? CFCopyUserName() : NULL; if (uName && !CFEqual(uName, userName)) { CFLog(kCFLogLevelError, CFSTR("CFCopyHomeDirectoryURLForUser(): Unable to get home directory for other user")); if (userName) CFRelease(userName); return NULL; } if (userName) CFRelease(userName); return CFCopyHomeDirectoryURL(); #else #error Dont know how to compute users home directories on this platform #endif }