Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -127,10 +127,18 @@ * \param str The string from which the data is written to the stream * \return The number of bytes written */ - (size_t)writeString: (OFString*)str; +/** + * Writes a string into the stream with a trailing newline. + * + * \param str The string from which the data is written to the stream + * \return The number of bytes written + */ +- (size_t)writeLine: (OFString*)str; + /** * Closes the stream. */ - close; @end Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -364,12 +364,33 @@ - (size_t)writeString: (OFString*)str { return [self writeNBytes: [str cStringLength] fromBuffer: [str cString]]; } + +- (size_t)writeLine: (OFString*)str +{ + size_t len = [str cStringLength]; + char *tmp; + + tmp = [self allocMemoryWithSize: len + 2]; + memcpy(tmp, [str cString], len); + tmp[len] = '\n'; + tmp[len + 1] = '\0'; + + @try { + return [self writeNBytes: len + 1 + fromBuffer: tmp]; + } @finally { + [self freeMemory: tmp]; + } + + /* Get rid of a warning, never reached anyway */ + assert(0); +} - close { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } @end