Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -6,10 +6,12 @@ * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ + +#include #import "OFObject.h" @class OFString; @class OFDataArray; @@ -264,10 +266,20 @@ * \param fmt A string used as format * \return The number of bytes written */ - (size_t)writeFormat: (OFString*)fmt, ...; +/** + * Writes a formatted string into the stream. + * + * \param fmt A string used as format + * \param args The arguments used in the format string + * \return The number of bytes written + */ +- (size_t)writeFormat: (OFString*)fmt + withArguments: (va_list)args; + /** * Closes the stream. */ - close; @end Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -611,26 +611,37 @@ } - (size_t)writeFormat: (OFString*)fmt, ... { va_list args; - char *t; + size_t ret; + + va_start(args, fmt); + ret = [self writeFormat: fmt + withArguments: args]; + va_end(args); + + return ret; +} + +- (size_t)writeFormat: (OFString*)fmt + withArguments: (va_list)args +{ size_t len; + char *t; if (fmt == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - va_start(args, fmt); if ((len = vasprintf(&t, [fmt cString], args)) == -1) { /* * This is only the most likely error to happen. Unfortunately, * there is no good way to check what really happened. */ @throw [OFOutOfMemoryException newWithClass: isa]; } - va_end(args); @try { return [self writeNBytes: len fromBuffer: t]; } @finally {