From d4eeab990d469e0ecee7ff1963b6940f77907413 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 3 Dec 2007 16:30:46 +0000 Subject: [PATCH] replaced usage of getCString on MacOS >= 10.4 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1556 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/NGStreams/ChangeLog | 3 +++ sope-core/NGStreams/NGCTextStream.m | 21 +++++++++++++++++---- sope-core/NGStreams/NGTextStream.m | 2 +- sope-core/NGStreams/Version | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/sope-core/NGStreams/ChangeLog b/sope-core/NGStreams/ChangeLog index 1a636f17..aa19ac03 100644 --- a/sope-core/NGStreams/ChangeLog +++ b/sope-core/NGStreams/ChangeLog @@ -1,5 +1,8 @@ 2007-12-03 Helge Hess + * 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) diff --git a/sope-core/NGStreams/NGCTextStream.m b/sope-core/NGStreams/NGCTextStream.m index a061c5a6..3e40a3df 100644 --- a/sope-core/NGStreams/NGCTextStream.m +++ b/sope-core/NGStreams/NGCTextStream.m @@ -1,5 +1,6 @@ /* - 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. @@ -290,12 +291,24 @@ static void _flushAtExit(void) { - (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) { @@ -313,7 +326,7 @@ static void _flushAtExit(void) { } } NS_HANDLER { - if (buf) { free(buf); buf = NULL; }; + if (buf != NULL) { free(buf); buf = NULL; }; [localException raise]; } NS_ENDHANDLER; diff --git a/sope-core/NGStreams/NGTextStream.m b/sope-core/NGStreams/NGTextStream.m index 755c90e1..dd9f522a 100644 --- a/sope-core/NGStreams/NGTextStream.m +++ b/sope-core/NGStreams/NGTextStream.m @@ -153,7 +153,7 @@ 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. */ diff --git a/sope-core/NGStreams/Version b/sope-core/NGStreams/Version index 5a9103fb..1e1b1b4f 100644 --- a/sope-core/NGStreams/Version +++ b/sope-core/NGStreams/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=54 +SUBMINOR_VERSION:=55 -- 2.39.5