2007-12-03 Helge Hess <me@helgehess.eu>
+ * NGCTextStream.m: replaced usage of getCString on MacOS > 10.4
+ (v4.7.55)
+
* NGTextStream.m: do not use exception handlers in combination with
varargs on MacOS >10.5 (v4.7.54)
/*
- Copyright (C) 2000-2005 SKYRIX Software AG
+ Copyright (C) 2000-2007 SKYRIX Software AG
+ Copyright (C) 2007 Helge Hess
This file is part of SOPE.
- (BOOL)writeString:(NSString *)_string {
unsigned char *str, *buf;
unsigned toGo;
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
+ NSStringEncoding enc = [NSString defaultCStringEncoding];
+ // TBD: better use -maximumLengthOf... and then search for \0
+ if ((toGo = [_string lengthOfBytesUsingEncoding:enc]) == 0)
+ return YES;
+
+ buf = str = calloc(toGo + 1, sizeof(unsigned char));
+ [_string getCString:(char *)str maxLength:toGo encoding:enc];
+#else
if ((toGo = [_string cStringLength]) == 0)
return YES;
-
+
buf = str = calloc(toGo + 1, sizeof(unsigned char));
- [_string getCString:(char *)str]; str[toGo] = '\0';
+ [_string getCString:(char *)str];
+#endif
+ str[toGo] = '\0';
NS_DURING {
while (toGo > 0) {
}
}
NS_HANDLER {
- if (buf) { free(buf); buf = NULL; };
+ if (buf != NULL) { free(buf); buf = NULL; };
[localException raise];
}
NS_ENDHANDLER;
va_start(ap, _format);
-#if MAC_OS_X_VERSION_MAX_ALLOWED > 1050
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
/* As soon as we add an exception handler on Leopard compilation
* breaks. Probably some GCC bug.
*/