BOOL __RSFileManagerContentsDirectory(RSFileManagerRef fmg, RSStringRef path, __autorelease RSErrorRef* error, __RSFileManagerContentsContext* context, BOOL shouldRecursion) { DIR *db; char filename[2*RSMaxPathSize] = {0}; struct dirent *p = nil; memcpy(filename, RSStringGetCStringPtr(path, RSStringEncodingMacRoman), RSStringGetLength(path)); db = opendir(filename); if (db == nil) { if (error) { RSDictionaryRef userInfo = RSDictionaryCreate(RSAllocatorSystemDefault, (const void**)RSErrorTargetKey, (const void**)&path, 1, RSDictionaryRSTypeContext); *error = RSErrorCreate(RSAllocatorSystemDefault, RSErrorDomainRSCoreFoundation, kErrExisting, userInfo); RSRelease(userInfo); RSAutorelease(*error); } return NO; } memset(filename, 0, 2*RSMaxPathSize); RSStringRef _fileNameStr = nil; RSStringRef _dirPath = nil; BOOL success = NO; while ((p = readdir(db))) { if((strcmp(p->d_name, ".") == 0) || (strcmp(p->d_name, "..") == 0)) continue; if (RSStringGetLength(path) > 0) { if (RSStringGetCStringPtr(path, RSStringEncodingMacRoman)[RSStringGetLength(path) - 1] == '/') sprintf(filename,"%s%s", RSStringGetCStringPtr(path, RSStringEncodingMacRoman), p->d_name); else sprintf(filename,"%s/%s", RSStringGetCStringPtr(path, RSStringEncodingMacRoman), p->d_name); } else sprintf(filename,"%s/%s", RSStringGetCStringPtr(path, RSStringEncodingUTF8), p->d_name); _fileNameStr = RSStringCreateWithCString(RSAllocatorSystemDefault, p->d_name, RSStringEncodingMacRoman); __RSFileManagerContentContextAddContent(context, _fileNameStr); if (p->d_type & DT_DIR && shouldRecursion) { _dirPath = RSStringCreateWithCString(RSAllocatorSystemDefault, filename, RSStringEncodingMacRoman); #if !__RSFileManagerContentsContextDoNotUseRSArray __RSFileManagerContentContextUpdateDirStack(context, _fileNameStr); #endif success = __RSFileManagerContentsDirectory(fmg, _dirPath, error, context, shouldRecursion); #if !__RSFileManagerContentsContextDoNotUseRSArray __RSFileManagerContentContextUpdateDirStack(context, nil); #endif RSRelease(_dirPath); _dirPath = nil; if (success == NO) return success; } RSRelease(_fileNameStr); _fileNameStr = nil; } closedir(db); return YES; }
static void __RSTimerClassDeallocate(RSTypeRef rs) { RSTimerRef timer = (RSTimerRef)rs; struct __RSTimer *_timer = (struct __RSTimer *)timer; if (__RSTimerIsTimer(timer)) { if (timer->_dps_timer) { // __dps_timer_invalid(timer->_dps_timer); if (__RSTimerIsSuspend(timer)) { RSExceptionCreateAndRaise(RSAllocatorSystemDefault, RSGenericException, RSSTR("BUG: RSTimer want to invalidate a suspend timer"), RSAutorelease(RSDictionaryCreateWithObjectsAndOKeys(RSAllocatorSystemDefault, timer, RSExceptionObject, nil))); return; } __dps_timer_release(timer->_dps_timer); } _timer->_dps_timer = nil; } memset(&_timer->_descriptor, 0, sizeof(struct __RSTimerDescriptor)); if (timer->_userInfo) RSRelease(timer->_userInfo); }
RSExport RSDateRef RSDateGetCurrent(RSAllocatorRef allocator) { return RSAutorelease(RSDateCreate(allocator, RSAbsoluteTimeGetCurrent())); }
RSExport RSDictionaryRef RSDictionaryWithData(RSDataRef data) { return RSAutorelease(RSDictionaryCreateWithData(RSAllocatorSystemDefault, data)); }
RSExport RSDictionaryRef RSDictionaryWithContentOfPath(RSStringRef path) { return RSAutorelease(RSDictionaryCreateWithContentOfPath(RSAllocatorSystemDefault, path)); }
RSExport RSDictionaryRef RSDictionaryWithObjectForKey(RSTypeRef object, RSTypeRef key) { return RSAutorelease(RSDictionaryCreateWithObjectsAndOKeys(RSAllocatorSystemDefault, object, key, NULL)); }
RSExport RSDictionaryRef RSDictionaryWithArray(RSArrayRef keys, RSArrayRef values, const RSDictionaryContext* context) { return RSAutorelease(RSDictionaryCreateWithArray(RSAllocatorSystemDefault, keys, values, context)); }
RSExport RSDictionaryRef RSDictionaryWithKeysAndValues(const void** keys, const void** values, const RSDictionaryContext* context, RSIndex count) { return RSAutorelease(RSDictionaryCreate(RSAllocatorSystemDefault, keys, values, count, context)); }