context->reallocate = __CFAllocatorGetReallocateFunction(&allocator->_context);
context->deallocate = __CFAllocatorGetDeallocateFunction(&allocator->_context);
context->preferredSize = __CFAllocatorGetPreferredSizeFunction(&allocator->_context);
+#if defined(__ppc__)
context->retain = (void *)((uintptr_t)context->retain & ~0x3);
context->release = (void *)((uintptr_t)context->release & ~0x3);
context->copyDescription = (void *)((uintptr_t)context->copyDescription & ~0x3);
context->reallocate = (void *)((uintptr_t)context->reallocate & ~0x3);
context->deallocate = (void *)((uintptr_t)context->deallocate & ~0x3);
context->preferredSize = (void *)((uintptr_t)context->preferredSize & ~0x3);
+#endif
}
void *_CFAllocatorAllocateGC(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint)
#endif
#if !defined(CF_INLINE)
- #if defined(__GNUC__)
- #define CF_INLINE static __inline__
+ #if defined(__GNUC__) && (__GNUC__ == 4)
+ #define CF_INLINE static __inline__ __attribute__((always_inline))
+ #elif defined(__GNUC__)
+ #define CF_INLINE static __inline__
#elif defined(__MWERKS__) || defined(__cplusplus)
#define CF_INLINE static inline
#elif defined(_MSC_VER)
# Misc additional options
#
-CURRENT_PROJECT_VERSION = 368.11
+CURRENT_PROJECT_VERSION = 368.18
# common items all build styles should be defining
CFLAGS += -DCF_BUILDING_CF=1
}
/* year arg is absolute year; Gregorian 2001 == year 0; 2001/1/1 = absolute date 0 */
-static int32_t __CFAbsoluteFromYMD(int32_t year, int8_t month, int8_t day) {
- int32_t absolute = 0, idx;
+static double __CFAbsoluteFromYMD(int32_t year, int8_t month, int8_t day) {
+ double absolute = 0.0;
+ int32_t idx;
+ int32_t b = year / 400; // take care of as many multiples of 400 years as possible
+ absolute += b * 146097.0;
+ year -= b * 400;
if (year < 0) {
for (idx = year; idx < 0; idx++)
absolute -= __CFDaysAfterMonth(0, idx, isleap(idx));
} else {
- for (idx = year - 1; 0 <= idx; idx--)
+ for (idx = 0; idx < year; idx++)
absolute += __CFDaysAfterMonth(0, idx, isleap(idx));
}
/* Now add the days into the original year */
SInt32 CFAbsoluteTimeGetWeekOfYear(CFAbsoluteTime at, CFTimeZoneRef tz) {
int32_t absolute, year;
int8_t month, day;
- int32_t absolute0101, dow0101;
CFAbsoluteTime fixedat;
if (NULL != tz) {
__CFGenericValidateType(tz, CFTimeZoneGetTypeID());
fixedat = at + (NULL != tz ? CFTimeZoneGetSecondsFromGMT(tz, at) : 0.0);
absolute = (int32_t)(float)floor(fixedat / 86400.0);
__CFYMDFromAbsolute(absolute, &year, &month, &day);
- absolute0101 = __CFAbsoluteFromYMD(year, 1, 1);
- dow0101 = (absolute0101 < 0) ? ((absolute0101 + 1) % 7 + 7) : (absolute0101 % 7 + 1);
+ double absolute0101 = __CFAbsoluteFromYMD(year, 1, 1);
+ int32_t dow0101 = __CFDoubleModToInt(absolute0101, 7) + 1;
/* First three and last three days of a year can end up in a week of a different year */
if (1 == month && day < 4) {
if ((day < 4 && 5 == dow0101) || (day < 3 && 6 == dow0101) || (day < 2 && 7 == dow0101)) {
}
}
if (12 == month && 28 < day) {
- int32_t absolute20101, dow20101;
- absolute20101 = __CFAbsoluteFromYMD(year + 1, 1, 1);
- dow20101 = (absolute20101 < 0) ? ((absolute20101 + 1) % 7 + 7) : (absolute20101 % 7 + 1);
+ double absolute20101 = __CFAbsoluteFromYMD(year + 1, 1, 1);
+ int32_t dow20101 = __CFDoubleModToInt(absolute20101, 7) + 1;
if ((28 < day && 4 == dow20101) || (29 < day && 3 == dow20101) || (30 < day && 2 == dow20101)) {
return 1;
}
switch (bundle->_binaryType) {
-#if defined(BINARY_SUPPORT_CFM)
+#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__)
case __CFBundleCFMBinary:
case __CFBundleUnreadableBinary:
result = _CFBundleCFMLoad(bundle);
break;
-#endif /* BINARY_SUPPORT_CFM */
+#endif /* BINARY_SUPPORT_CFM && __ppc__ */
#if defined(BINARY_SUPPORT_DYLD)
case __CFBundleDYLDBundleBinary:
result = _CFBundleDYLDLoadBundle(bundle);
_CFPlugInWillUnload(bundle);
switch (bundle->_binaryType) {
-#if defined(BINARY_SUPPORT_CFM)
+#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__)
case __CFBundleCFMBinary:
_CFBundleCFMUnload(bundle);
break;
-#endif /* BINARY_SUPPORT_CFM */
+#endif /* BINARY_SUPPORT_CFM && __ppc__ */
#if defined(BINARY_SUPPORT_DYLD)
case __CFBundleDYLDBundleBinary:
_CFBundleDYLDUnloadBundle(bundle);
}
switch (bundle->_binaryType) {
-#if defined(BINARY_SUPPORT_CFM)
+#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__)
case __CFBundleCFMBinary:
tvp = _CFBundleCFMGetSymbolByName(bundle, funcName, kTVectorCFragSymbol);
break;
-#endif /* BINARY_SUPPORT_CFM */
+#endif /* BINARY_SUPPORT_CFM && __ppc__ */
#if defined(BINARY_SUPPORT_DYLD)
case __CFBundleDYLDBundleBinary:
case __CFBundleDYLDFrameworkBinary:
}
switch (bundle->_binaryType) {
-#if defined(BINARY_SUPPORT_CFM)
+#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__)
case __CFBundleCFMBinary:
return _CFBundleCFMGetSymbolByName(bundle, funcName, kTVectorCFragSymbol);
break;
-#endif /* BINARY_SUPPORT_CFM */
+#endif /* BINARY_SUPPORT_CFM && __ppc__ */
#if defined(BINARY_SUPPORT_DYLD)
case __CFBundleDYLDBundleBinary:
case __CFBundleDYLDFrameworkBinary:
}
switch (bundle->_binaryType) {
-#if defined(BINARY_SUPPORT_CFM)
+#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__)
case __CFBundleCFMBinary:
dp = _CFBundleCFMGetSymbolByName(bundle, symbolName, kDataCFragSymbol);
break;
-#endif /* BINARY_SUPPORT_CFM */
+#endif /* BINARY_SUPPORT_CFM && __ppc__ */
#if defined(BINARY_SUPPORT_DYLD)
case __CFBundleDYLDBundleBinary:
case __CFBundleDYLDFrameworkBinary:
extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsForHint(CFStringRef hint);
#endif
-#if defined(BINARY_SUPPORT_CFM)
+#if defined(BINARY_SUPPORT_CFM) && defined(__ppc__)
// CFM API
#if defined(__MACOS8__)
#include <CodeFragments.h>
extern void _CFBundleCFMUnload(CFBundleRef bundle);
extern void *__CFBundleCFMGetSymbol(void *connID, ConstStr255Param name, CFragSymbolClass class);
extern void *_CFBundleCFMGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName, CFragSymbolClass class);
-#endif /* BINARY_SUPPORT_CFM */
+#endif /* BINARY_SUPPORT_CFM && __ppc__ */
#if defined(BINARY_SUPPORT_DLL)
extern Boolean _CFBundleDLLLoad(CFBundleRef bundle);
startOfExtension = _CFStartOfPathExtension(buff, strLen);
if (((strLen - startOfExtension == 4) || (strLen - startOfExtension == 5)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'a') && (buff[startOfExtension+2] == (UniChar)'p') && (buff[startOfExtension+3] == (UniChar)'p') && ((strLen - startOfExtension == 4) || (buff[startOfExtension+4] == (UniChar)'/'))) {
// This is an app
- *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL'
+ *packageType = 0x4150504c; // 'APPL'
} else if (((strLen - startOfExtension == 6) || (strLen - startOfExtension == 7)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'d') && (buff[startOfExtension+2] == (UniChar)'e') && (buff[startOfExtension+3] == (UniChar)'b') && (buff[startOfExtension+4] == (UniChar)'u') && (buff[startOfExtension+5] == (UniChar)'g') && ((strLen - startOfExtension == 6) || (buff[startOfExtension+6] == (UniChar)'/'))) {
// This is an app (debug version)
- *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL'
+ *packageType = 0x4150504c; // 'APPL'
} else if (((strLen - startOfExtension == 8) || (strLen - startOfExtension == 9)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'p') && (buff[startOfExtension+2] == (UniChar)'r') && (buff[startOfExtension+3] == (UniChar)'o') && (buff[startOfExtension+4] == (UniChar)'f') && (buff[startOfExtension+5] == (UniChar)'i') && (buff[startOfExtension+6] == (UniChar)'l') && (buff[startOfExtension+7] == (UniChar)'e') && ((strLen - startOfExtension == 8) || (buff[startOfExtension+8] == (UniChar)'/'))) {
// This is an app (profile version)
- *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL'
+ *packageType = 0x4150504c; // 'APPL'
} else if (((strLen - startOfExtension == 8) || (strLen - startOfExtension == 9)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'s') && (buff[startOfExtension+2] == (UniChar)'e') && (buff[startOfExtension+3] == (UniChar)'r') && (buff[startOfExtension+4] == (UniChar)'v') && (buff[startOfExtension+5] == (UniChar)'i') && (buff[startOfExtension+6] == (UniChar)'c') && (buff[startOfExtension+7] == (UniChar)'e') && ((strLen - startOfExtension == 8) || (buff[startOfExtension+8] == (UniChar)'/'))) {
// This is a service
- *packageType = CFSwapInt32BigToHost(0x4150504c); // 'APPL'
+ *packageType = 0x4150504c; // 'APPL'
} else if (((strLen - startOfExtension == 10) || (strLen - startOfExtension == 11)) && (buff[startOfExtension] == (UniChar)'.') && (buff[startOfExtension+1] == (UniChar)'f') && (buff[startOfExtension+2] == (UniChar)'r') && (buff[startOfExtension+3] == (UniChar)'a') && (buff[startOfExtension+4] == (UniChar)'m') && (buff[startOfExtension+5] == (UniChar)'e') && (buff[startOfExtension+6] == (UniChar)'w') && (buff[startOfExtension+7] == (UniChar)'o') && (buff[startOfExtension+8] == (UniChar)'r') && (buff[startOfExtension+9] == (UniChar)'k') && ((strLen - startOfExtension == 10) || (buff[startOfExtension+10] == (UniChar)'/'))) {
// This is a framework
- *packageType = CFSwapInt32BigToHost(0x464d574b); // 'FMWK'
+ *packageType = 0x464d574b; // 'FMWK'
} else {
// Default to BNDL for generic bundle
- *packageType = CFSwapInt32BigToHost(0x424e444C); // 'BNDL'
+ *packageType = 0x424e444c; // 'BNDL'
}
}
retVal = true;
CFURLRef bundleURL = CFBundleCopyBundleURL(bundle);
if (!_CFBundleGetPackageInfoInDirectoryWithInfoDictionary(CFGetAllocator(bundle), bundleURL, CFBundleGetInfoDictionary(bundle), packageType, packageCreator)) {
if (packageType != NULL) {
- *packageType = CFSwapInt32BigToHost(0x424e444C); // 'BNDL'
+ *packageType = 0x424e444c; // 'BNDL'
}
if (packageCreator != NULL) {
*packageCreator = 0x3f3f3f3f; // '????'
void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName) {
CFPreferencesDomainRef appDomain;
+ void *defs = NULL;
+ __CFSpinLock(&userDefaultsLock);
+ defs = userDefaults;
+ __CFSpinUnlock(&userDefaultsLock);
+ CF_OBJC_KVO_WILLCHANGE(defs, defaultName);
__CFSpinLock(&__CFApplicationPreferencesLock);
appDomain = _CFPreferencesStandardDomain(self->_appName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if(appDomain) {
}
}
__CFSpinUnlock(&__CFApplicationPreferencesLock);
+ CF_OBJC_KVO_DIDCHANGE(defs, defaultName);
}
static Boolean _CFApplicationPreferencesSynchronizeNoLock(_CFApplicationPreferences *self) {
}
#endif
+static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef domainName, CFStringRef userName, CFStringRef hostName, unsigned long safeLevel);
+
static unsigned long __CFSafeLaunchLevel = 0;
static CFURLRef _preferencesDirectoryForUserHostSafetyLevel(CFStringRef userName, CFStringRef hostName, unsigned long safeLevel) {
int fd = -1;
char auxPath[CFMaxPathSize + 16];
char cpath[CFMaxPathSize];
- int fsyncErr = 0;
+ uid_t owner = getuid();
+ gid_t group = getgid();
+ Boolean writingFileAsRoot = ((getuid() != geteuid()) && (geteuid() == 0));
if (!CFURLGetFileSystemRepresentation(url, true, cpath, CFMaxPathSize)) {
return false;
}
- if (-1 == mode) {
+
+ if (-1 == mode || writingFileAsRoot) {
struct stat statBuf;
- mode = (0 == stat(cpath, &statBuf)) ? statBuf.st_mode : 0600;
+ if (0 == stat(cpath, &statBuf)) {
+ mode = statBuf.st_mode;
+ owner = statBuf.st_uid;
+ group = statBuf.st_gid;
+ } else {
+ mode = 0664;
+ if (writingFileAsRoot && (0 == strncmp(cpath, "/Library/Preferences", 20))) {
+ owner = geteuid();
+ group = 80;
+ }
+ }
}
+
if (atomic) {
CFURLRef dir = CFURLCreateCopyDeletingLastPathComponent(NULL, url);
CFURLRef tempFile = CFURLCreateCopyAppendingPathComponent(NULL, dir, CFSTR("cf#XXXXX"), false);
} else {
fd = open(cpath, O_WRONLY|O_CREAT|O_TRUNC, mode);
}
+
if (fd < 0) return false;
+
if (length && (write(fd, bytes, length) != length || fsync(fd) < 0)) {
int saveerr = thread_errno();
close(fd);
thread_set_errno(saveerr);
return false;
}
+
close(fd);
+
if (atomic) {
// preserve the mode as passed in originally
chmod(auxPath, mode);
unlink(auxPath);
return false;
}
+
+ // If the file was renamed successfully and we wrote it as root we need to reset the owner & group as they were.
+ if (writingFileAsRoot) {
+ chown(cpath, owner, group);
+ }
}
return true;
}
#include <CoreFoundation/CFMachPort.h>
#include <CoreFoundation/CFRunLoop.h>
#include <CoreFoundation/CFDictionary.h>
+#include <CoreFoundation/CFByteOrder.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <mach/notify.h>
static void __CFNotifyDeadMachPort(CFMachPortRef port, void *msg, CFIndex size, void *info) {
mach_msg_header_t *header = (mach_msg_header_t *)msg;
if (header && header->msgh_id == MACH_NOTIFY_DEAD_NAME) {
- mach_port_t dead_port = ((mach_dead_name_notification_t *)msg)->not_port;
- CFMachPortRef existing;
- /* If the CFMachPort has already been invalidated, it won't be found here. */
- __CFSpinLock(&__CFAllMachPortsLock);
- if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) {
- CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port);
- CFRetain(existing);
- __CFSpinUnlock(&__CFAllMachPortsLock);
- CFMachPortInvalidate(existing);
- CFRelease(existing);
- } else {
- __CFSpinUnlock(&__CFAllMachPortsLock);
- }
- /* Delete port reference we got for this notification */
- mach_port_deallocate(mach_task_self(), dead_port);
+ mach_port_t dead_port = ((mach_dead_name_notification_t *)msg)->not_port;
+ if (((mach_dead_name_notification_t *)msg)->NDR.int_rep != NDR_record.int_rep) {
+ dead_port = CFSwapInt32(dead_port);
+ }
+ CFMachPortRef existing;
+ /* If the CFMachPort has already been invalidated, it won't be found here. */
+ __CFSpinLock(&__CFAllMachPortsLock);
+ if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) {
+ CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port);
+ CFRetain(existing);
+ __CFSpinUnlock(&__CFAllMachPortsLock);
+ CFMachPortInvalidate(existing);
+ CFRelease(existing);
+ } else {
+ __CFSpinUnlock(&__CFAllMachPortsLock);
+ }
+ /* Delete port reference we got for this notification */
+ mach_port_deallocate(mach_task_self(), dead_port);
} else if (header && header->msgh_id == MACH_NOTIFY_PORT_DELETED) {
- mach_port_t dead_port = ((mach_port_deleted_notification_t *)msg)->not_port;
- CFMachPortRef existing;
- /* If the CFMachPort has already been invalidated, it won't be found here. */
- __CFSpinLock(&__CFAllMachPortsLock);
- if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) {
- CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port);
- CFRetain(existing);
- __CFSpinUnlock(&__CFAllMachPortsLock);
- CFMachPortInvalidate(existing);
- CFRelease(existing);
- } else {
- __CFSpinUnlock(&__CFAllMachPortsLock);
- }
- /* Delete port reference we got for this notification */
-// Don't do this, since this always fails, and could cause trouble
-// mach_port_deallocate(mach_task_self(), dead_port);
+ mach_port_t dead_port = ((mach_port_deleted_notification_t *)msg)->not_port;
+ if (((mach_dead_name_notification_t *)msg)->NDR.int_rep != NDR_record.int_rep) {
+ dead_port = CFSwapInt32(dead_port);
+ }
+ CFMachPortRef existing;
+ /* If the CFMachPort has already been invalidated, it won't be found here. */
+ __CFSpinLock(&__CFAllMachPortsLock);
+ if (NULL != __CFAllMachPorts && CFDictionaryGetValueIfPresent(__CFAllMachPorts, (void *)dead_port, (const void **)&existing)) {
+ CFDictionaryRemoveValue(__CFAllMachPorts, (void *)dead_port);
+ CFRetain(existing);
+ __CFSpinUnlock(&__CFAllMachPortsLock);
+ CFMachPortInvalidate(existing);
+ CFRelease(existing);
+ } else {
+ __CFSpinUnlock(&__CFAllMachPortsLock);
+ }
+ /* Delete port reference we got for this notification */
+ // Don't do this, since this always fails, and could cause trouble
+ // mach_port_deallocate(mach_task_self(), dead_port);
}
}
// this is assuming viramas are only in BMP ???
if ((str1Char == COMBINING_GRAPHEME_JOINER) || (otherChar == COMBINING_GRAPHEME_JOINER) || (otherChar == ZERO_WIDTH_JOINER) || ((otherChar >= HANGUL_CHOSEONG_START) && (otherChar <= HANGUL_JONGSEONG_END)) || (CFUniCharGetCombiningPropertyForCharacter(otherChar, combClassBMP) == 9)) {
- CFRange clusterRange = CFStringGetRangeOfCharacterClusterAtIndex(string, str1Index, kCFStringGramphemeCluster);
+ CFRange clusterRange = CFStringGetRangeOfCharacterClusterAtIndex(string, str1Index - 1, kCFStringGramphemeCluster);
if (str1Index < (clusterRange.location + clusterRange.length)) match = false;
}