mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
* Headers/gnustep/base/GSObjCRuntime.h/m (GSPrintf),
* Headers/gnustep/base/NSObjCRuntime.h (GSPrintf), * Source/NSLog.m (GSPrintf): Moved implementation from NSLog.m * to GSObjCRuntime.m and declaration from NSObjCRuntime.h to GSObjCRuntime.h. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17084 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
54a9e66dc5
commit
584c139a1b
5 changed files with 77 additions and 62 deletions
|
@ -186,10 +186,11 @@ NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler;
|
|||
* the lower level NSLogv() function (which this function uses).
|
||||
* </p>
|
||||
* <p>GNUstep provides powerful alternatives for logging ... see
|
||||
* NSDebugLog(), NSWarnLog(), and GSPrintf() for example. We recommend
|
||||
* NSDebugLog(), NSWarnLog() and GSPrintf() for example. We recommend
|
||||
* the use of NSDebugLog() and its relatives for debug purposes, and
|
||||
* GSPrintf() for general log messages, with NSLog() being reserved
|
||||
* for reporting possible/likely errors.
|
||||
* for reporting possible/likely errors. GSPrintf() is declared in
|
||||
* GSObjCRuntime.h.
|
||||
* </p>
|
||||
*/
|
||||
void
|
||||
|
@ -272,62 +273,3 @@ NSLogv (NSString* format, va_list args)
|
|||
RELEASE(arp);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prints a message to fptr using the format string provided and any
|
||||
* additional arguments. The format string is interpreted as by
|
||||
* the NSString formatted initialisers, and understands the '%@' syntax
|
||||
* for printing an object.
|
||||
* </p>
|
||||
* <p>The data is written to the file pointer in the default CString
|
||||
* encoding if possible, as a UTF8 string otherwise.
|
||||
* </p>
|
||||
* <p>This function is recommended for printing general log messages.
|
||||
* For debug messages use NSDebugLog() and friends. For error logging
|
||||
* use NSLog(), and for warnings you might consider NSWarnLog().
|
||||
* </p>
|
||||
*/
|
||||
BOOL
|
||||
GSPrintf (FILE *fptr, NSString* format, ...)
|
||||
{
|
||||
static Class stringClass = 0;
|
||||
static NSStringEncoding enc;
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
va_list ap;
|
||||
NSString *message;
|
||||
NSData *data;
|
||||
BOOL ok = NO;
|
||||
|
||||
if (stringClass == 0)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
if (stringClass == 0)
|
||||
{
|
||||
stringClass = [NSString class];
|
||||
enc = [stringClass defaultCStringEncoding];
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
message = [stringClass allocWithZone: NSDefaultMallocZone()];
|
||||
va_start (ap, format);
|
||||
message = [message initWithFormat: format locale: nil arguments: ap];
|
||||
va_end (ap);
|
||||
data = [message dataUsingEncoding: enc];
|
||||
if (data == nil)
|
||||
{
|
||||
data = [message dataUsingEncoding: NSUTF8StringEncoding];
|
||||
}
|
||||
RELEASE(message);
|
||||
|
||||
if (data != nil)
|
||||
{
|
||||
unsigned int length = [data length];
|
||||
|
||||
if (length == 0 || fwrite([data bytes], 1, length, fptr) == length)
|
||||
{
|
||||
ok = YES;
|
||||
}
|
||||
}
|
||||
RELEASE(arp);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue