X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sope-core%2FNGStreams%2FNGCTextStream.m;fp=sope-core%2FNGStreams%2FNGCTextStream.m;h=3e40a3df85c4df3c225268f6cf328a2fe6e95fe2;hb=d4eeab990d469e0ecee7ff1963b6940f77907413;hp=a061c5a6f981869b7ff667a668bebf260d55f20f;hpb=b44f465984a6444dc4ed079cf1ccd52332e8f84e;p=sope 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;