Index: src/OFDataArray+Hashing.m ================================================================== --- src/OFDataArray+Hashing.m +++ src/OFDataArray+Hashing.m @@ -28,11 +28,11 @@ - (OFString*)MD5Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFMD5Hash MD5Hash]; uint8_t *digest; - char cRet[OF_MD5_DIGEST_SIZE * 2]; + char retCString[OF_MD5_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: data ofSize: count * itemSize]; digest = [hash digest]; @@ -41,26 +41,26 @@ uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; - cRet[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); - cRet[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); + retCString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); + retCString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } [pool release]; - return [OFString stringWithCString: cRet + return [OFString stringWithCString: retCString length: 32]; } - (OFString*)SHA1Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFSHA1Hash SHA1Hash]; uint8_t *digest; - char cRet[OF_SHA1_DIGEST_SIZE * 2]; + char retCString[OF_SHA1_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: data ofSize: count * itemSize]; digest = [hash digest]; @@ -69,15 +69,15 @@ uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; - cRet[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); - cRet[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); + retCString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); + retCString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } [pool release]; - return [OFString stringWithCString: cRet + return [OFString stringWithCString: retCString length: 40]; } @end Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -32,13 +32,13 @@ /** * \brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFSeekableStream { - int fd; + int fileDescriptor; BOOL closable; - BOOL eos; + BOOL isAtEndOfStream; } /** * \param path The path to the file to open as a string * \param mode The mode in which the file should be opened as a string @@ -46,15 +46,15 @@ */ + fileWithPath: (OFString*)path mode: (OFString*)mode; /** - * \param fd A file descriptor, returned from for example open(). - * It is not closed when the OFFile object is deallocated! + * \param fileDescriptor A file descriptor, returned from for example open(). + * It is not closed when the OFFile object is deallocated! * \return A new autoreleased OFFile */ -+ fileWithFileDescriptor: (int)fd; ++ fileWithFileDescriptor: (int)fileDescriptor; /** * \return The path of the current working directory */ + (OFString*)currentDirectoryPath; @@ -127,24 +127,24 @@ #endif /** * Copies a file. * - * \param from The file to copy - * \param to The destination path + * \param source The file to copy + * \param destination The destination path */ -+ (void)copyFileAtPath: (OFString*)from - toPath: (OFString*)to; ++ (void)copyFileAtPath: (OFString*)source + toPath: (OFString*)destination; /** * Renames a file. * - * \param from The file to rename - * \param to The new name + * \param source The file to rename + * \param destination The new name */ -+ (void)renameFileAtPath: (OFString*)from - toPath: (OFString*)to; ++ (void)renameFileAtPath: (OFString*)source + toPath: (OFString*)destination; /** * Deletes a file. * * \param path The path to the file of which should be deleted as a string @@ -162,28 +162,28 @@ /** * Hardlinks a file. * * Not available on Windows. * - * \param src The path to the file of which should be linked as a string - * \param dest The path to where the file should be linked as a string + * \param source The path to the file of which should be linked as a string + * \param destination The path to where the file should be linked as a string */ -+ (void)linkFileAtPath: (OFString*)src - toPath: (OFString*)dest; ++ (void)linkFileAtPath: (OFString*)source + toPath: (OFString*)destination; #endif #if !defined(_WIN32) && !defined(_PSP) /** * Symlinks a file. * * Not available on Windows. * - * \param src The path to the file of which should be symlinked as a string - * \param dest The path to where the file should be symlinked as a string + * \param source The path to the file of which should be symlinked as a string + * \param destination The path to where the file should be symlinked as a string */ -+ (void)symlinkFileAtPath: (OFString*)src - toPath: (OFString*)dest; ++ (void)symlinkFileAtPath: (OFString*)source + toPath: (OFString*)destination; #endif /** * Initializes an already allocated OFFile. * @@ -195,14 +195,14 @@ mode: (OFString*)mode; /** * Initializes an already allocated OFFile. * - * \param fd A file descriptor, returned from for example open(). - * It is not closed when the OFFile object is deallocated! + * \param fileDescriptor A file descriptor, returned from for example open(). + * It is not closed when the OFFile object is deallocated! */ -- initWithFileDescriptor: (int)fd; +- initWithFileDescriptor: (int)fileDescriptor; @end #ifdef __cplusplus extern "C" { #endif Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -49,10 +49,11 @@ #import "OFDeleteFileFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" +#import "OFOutOfMemoryException.h" #import "OFReadFailedException.h" #import "OFRenameFileFailedException.h" #import "OFSeekFailedException.h" #import "OFSymlinkFailedException.h" #import "OFWriteFailedException.h" @@ -120,27 +121,27 @@ return -1; } void -of_log(OFConstantString *fmt, ...) +of_log(OFConstantString *format, ...) { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFDate *date; - OFString *date_str, *me, *msg; - va_list args; + OFString *dateString, *me, *msg; + va_list arguments; date = [OFDate date]; - date_str = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; + dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; me = [[OFApplication programName] lastPathComponent]; - va_start(args, fmt); - msg = [[[OFString alloc] initWithFormat: fmt - arguments: args] autorelease]; - va_end(args); + va_start(arguments, format); + msg = [[[OFString alloc] initWithFormat: format + arguments: arguments] autorelease]; + va_end(arguments); - [of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", date_str, + [of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, [date microsecond] / 1000, me, getpid(), msg]; [pool release]; } @@ -168,24 +169,25 @@ { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } -+ fileWithFileDescriptor: (int)fd_ ++ fileWithFileDescriptor: (int)filedescriptor { - return [[[self alloc] initWithFileDescriptor: fd_] autorelease]; + return [[[self alloc] + initWithFileDescriptor: filedescriptor] autorelease]; } + (OFString*)currentDirectoryPath { OFString *ret; - char *buf = getcwd(NULL, 0); + char *buffer = getcwd(NULL, 0); @try { - ret = [OFString stringWithCString: buf]; + ret = [OFString stringWithCString: buffer]; } @finally { - free(buf); + free(buffer); } return ret; } @@ -262,20 +264,21 @@ } #else HANDLE handle; WIN32_FIND_DATA fd; + pool = [[OFAutoreleasePool alloc] init]; path = [path stringByAppendingString: @"\\*"]; if ((handle = FindFirstFile([path cString], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenFileFailedException newWithClass: self path: path mode: @"r"]; @try { - pool = [[OFAutoreleasePool alloc] init]; + OFAutoreleasePool pool2 = [[OFAutoreleasePool alloc] init]; do { OFString *file; if (!strcmp(fd.cFileName, ".") || @@ -283,17 +286,19 @@ continue; file = [OFString stringWithCString: fd.cFileName]; [files addObject: file]; - [pool releaseObjects]; + [pool2 releaseObjects]; } while (FindNextFile(handle, &fd)); - [pool release]; + [pool2 release]; } @finally { FindClose(handle); } + + [pool release]; #endif /* * Class swizzle the array to be immutable. We declared the return type * to be OFArray*, so it can't be modified anyway. But not swizzling it @@ -318,23 +323,23 @@ if (chmod([path cString], mode)) @throw [OFChangeFileModeFailedException newWithClass: self path: path mode: mode]; # else - DWORD attrs = GetFileAttributes([path cString]); + DWORD attributes = GetFileAttributes([path cString]); - if (attrs == INVALID_FILE_ATTRIBUTES) + if (attributes == INVALID_FILE_ATTRIBUTES) @throw [OFChangeFileModeFailedException newWithClass: self path: path mode: mode]; if ((mode / 100) & 2) - attrs &= ~FILE_ATTRIBUTE_READONLY; + attributes &= ~FILE_ATTRIBUTE_READONLY; else - attrs |= FILE_ATTRIBUTE_READONLY; + attributes |= FILE_ATTRIBUTE_READONLY; - if (!SetFileAttributes([path cString], attrs)) + if (!SetFileAttributes([path cString], attributes)) @throw [OFChangeFileModeFailedException newWithClass: self path: path mode: mode]; # endif } @@ -370,33 +375,33 @@ [mutex lock]; @try { # endif if (owner != nil) { - struct passwd *pw; + struct passwd *passwd; - if ((pw = getpwnam([owner cString])) == NULL) + if ((passwd = getpwnam([owner cString])) == NULL) @throw [OFChangeFileOwnerFailedException newWithClass: self path: path owner: owner group: group]; - uid = pw->pw_uid; + uid = passwd->pw_uid; } if (group != nil) { - struct group *gr; + struct group *group_; - if ((gr = getgrnam([group cString])) == NULL) + if ((group_ = getgrnam([group cString])) == NULL) @throw [OFChangeFileOwnerFailedException newWithClass: self path: path owner: owner group: group]; - gid = gr->gr_gid; + gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { [mutex unlock]; } @@ -408,74 +413,83 @@ owner: owner group: group]; } #endif -+ (void)copyFileAtPath: (OFString*)from - toPath: (OFString*)to ++ (void)copyFileAtPath: (OFString*)source + toPath: (OFString*)destination { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; BOOL override; - OFFile *src; - OFFile *dest; - char buf[4096]; + OFFile *sourceFile = nil; + OFFile *destinationFile = nil; + char *buffer; - if ([self directoryExistsAtPath: to]) { - OFString *filename = [from lastPathComponent]; - to = [OFString stringWithPath: to, filename, nil]; + if ([self directoryExistsAtPath: destination]) { + OFString *filename = [source lastPathComponent]; + destination = [OFString stringWithPath: destination, filename, + nil]; } - override = [self fileExistsAtPath: to]; + override = [self fileExistsAtPath: destination]; - src = nil; - dest = nil; + if ((buffer = malloc(of_pagesize)) == NULL) + @throw [OFOutOfMemoryException newWithClass: self + requestedSize: of_pagesize]; @try { - src = [OFFile fileWithPath: from - mode: @"rb"]; - dest = [OFFile fileWithPath: to - mode: @"wb"]; - - while (![src isAtEndOfStream]) { - size_t len = [src readNBytes: 4096 - intoBuffer: buf]; - [dest writeNBytes: len - fromBuffer: buf]; + sourceFile = [OFFile fileWithPath: source + mode: @"rb"]; + destinationFile = [OFFile fileWithPath: destination + mode: @"wb"]; + + while (![sourceFile isAtEndOfStream]) { + size_t len = [sourceFile readNBytes: of_pagesize + intoBuffer: buffer]; + [destinationFile writeNBytes: len + fromBuffer: buffer]; } #if !defined(_WIN32) && !defined(_PSP) if (!override) { struct stat s; - if (fstat(src->fd, &s) == 0) - fchmod(dest->fd, s.st_mode); + if (fstat(sourceFile->fileDescriptor, &s) == 0) + fchmod(destinationFile->fileDescriptor, + s.st_mode); } #endif } @finally { - [src close]; - [dest close]; + [sourceFile close]; + [destinationFile close]; + free(buffer); } [pool release]; } -+ (void)renameFileAtPath: (OFString*)from - toPath: (OFString*)to ++ (void)renameFileAtPath: (OFString*)source + toPath: (OFString*)destination { - if ([self directoryExistsAtPath: to]) { - OFString *filename = [from lastPathComponent]; - to = [OFString stringWithPath: to, filename, nil]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + + if ([self directoryExistsAtPath: destination]) { + OFString *filename = [source lastPathComponent]; + destination = [OFString stringWithPath: destination, filename, + nil]; } #ifndef _WIN32 - if (rename([from cString], [to cString])) + if (rename([source cString], [destination cString])) #else - if (!MoveFile([from cString], [to cString])) + if (!MoveFile([source cString], [destination cString])) #endif @throw [OFRenameFileFailedException newWithClass: self - sourcePath: from - destinationPath: to]; + sourcePath: source + destinationPath: destination]; + + [pool release]; } + (void)deleteFileAtPath: (OFString*)path { #ifndef _WIN32 @@ -493,38 +507,48 @@ @throw [OFDeleteDirectoryFailedException newWithClass: self path: path]; } #ifndef _WIN32 -+ (void)linkFileAtPath: (OFString*)src - toPath: (OFString*)dest ++ (void)linkFileAtPath: (OFString*)source + toPath: (OFString*)destination { - if ([self directoryExistsAtPath: dest]) { - OFString *filename = [src lastPathComponent]; - dest = [OFString stringWithPath: dest, filename, nil]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + + if ([self directoryExistsAtPath: destination]) { + OFString *filename = [source lastPathComponent]; + destination = [OFString stringWithPath: destination, filename, + nil]; } - if (link([src cString], [dest cString]) != 0) + if (link([source cString], [destination cString]) != 0) @throw [OFLinkFailedException newWithClass: self - sourcePath: src - destinationPath: dest]; + sourcePath: source + destinationPath: destination]; + + [pool release]; } #endif #if !defined(_WIN32) && !defined(_PSP) -+ (void)symlinkFileAtPath: (OFString*)src - toPath: (OFString*)dest ++ (void)symlinkFileAtPath: (OFString*)source + toPath: (OFString*)destination { - if ([self directoryExistsAtPath: dest]) { - OFString *filename = [src lastPathComponent]; - dest = [OFString stringWithPath: dest, filename, nil]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + + if ([self directoryExistsAtPath: destination]) { + OFString *filename = [source lastPathComponent]; + destination = [OFString stringWithPath: destination, filename, + nil]; } - if (symlink([src cString], [dest cString]) != 0) + if (symlink([source cString], [destination cString]) != 0) @throw [OFSymlinkFailedException newWithClass: self - sourcePath: src - destinationPath: dest]; + sourcePath: source + destinationPath: destination]; + + [pool release]; } #endif - init { @@ -544,11 +568,12 @@ if ((flags = parse_mode([mode cString])) == -1) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - if ((fd = open([path cString], flags, DEFAULT_MODE)) == -1) + if ((fileDescriptor = open([path cString], flags, + DEFAULT_MODE)) == -1) @throw [OFOpenFileFailedException newWithClass: isa path: path mode: mode]; closable = YES; @@ -558,106 +583,108 @@ } return self; } -- initWithFileDescriptor: (int)fd_ +- initWithFileDescriptor: (int)fileDescriptor_ { self = [super init]; - fd = fd_; + fileDescriptor = fileDescriptor_; return self; } - (BOOL)_isAtEndOfStream { - if (fd == -1) + if (fileDescriptor == -1) return YES; - return eos; + return isAtEndOfStream; } -- (size_t)_readNBytes: (size_t)size - intoBuffer: (char*)buf +- (size_t)_readNBytes: (size_t)length + intoBuffer: (char*)buffer { - size_t ret; + size_t retLength; - if (fd == -1 || eos) + if (fileDescriptor == -1 || isAtEndOfStream) @throw [OFReadFailedException newWithClass: isa stream: self - requestedSize: size]; - if ((ret = read(fd, buf, size)) == 0) - eos = YES; + requestedLength: length]; + if ((retLength = read(fileDescriptor, buffer, length)) == 0) + isAtEndOfStream = YES; - return ret; + return retLength; } -- (size_t)_writeNBytes: (size_t)size - fromBuffer: (const char*)buf +- (size_t)_writeNBytes: (size_t)length + fromBuffer: (const char*)buffer { - size_t ret; + size_t retLength; - if (fd == -1 || eos || (ret = write(fd, buf, size)) < size) + if (fileDescriptor == -1 || isAtEndOfStream || + (retLength = write(fileDescriptor, buffer, length)) < length) @throw [OFWriteFailedException newWithClass: isa stream: self - requestedSize: size]; + requestedLength: length]; - return ret; + return retLength; } - (void)_seekToOffset: (off_t)offset { - if (lseek(fd, offset, SEEK_SET) == -1) + if (lseek(fileDescriptor, offset, SEEK_SET) == -1) @throw [OFSeekFailedException newWithClass: isa stream: self offset: offset whence: SEEK_SET]; } - (off_t)_seekForwardWithOffset: (off_t)offset { - off_t ret; + off_t retOffset; - if ((ret = lseek(fd, offset, SEEK_CUR)) == -1) + if ((retOffset = lseek(fileDescriptor, offset, SEEK_CUR)) == -1) @throw [OFSeekFailedException newWithClass: isa stream: self offset: offset whence: SEEK_CUR]; - return ret; + return retOffset; } - (off_t)_seekToOffsetRelativeToEnd: (off_t)offset { - off_t ret; + off_t retOffset; - if ((ret = lseek(fd, offset, SEEK_END)) == -1) + if ((retOffset = lseek(fileDescriptor, offset, SEEK_END)) == -1) @throw [OFSeekFailedException newWithClass: isa stream: self offset: offset whence: SEEK_END]; - return ret; + return retOffset; } - (int)fileDescriptor { - return fd; + return fileDescriptor; } - (void)close { - if (fd != -1) - close(fd); - fd = -1; + if (fileDescriptor != -1) + close(fileDescriptor); + + fileDescriptor = -1; } - (void)dealloc { - if (closable && fd != -1) - close(fd); + if (closable && fileDescriptor != -1) + close(fileDescriptor); [super dealloc]; } @end Index: src/OFSeekableStream.m ================================================================== --- src/OFSeekableStream.m +++ src/OFSeekableStream.m @@ -41,34 +41,34 @@ { [self _seekToOffset: offset]; [self freeMemory: cache]; cache = NULL; - cacheLen = 0; + cacheLength = 0; } - (off_t)seekForwardWithOffset: (off_t)offset { - off_t ret; + off_t retOffset; - ret = [self _seekForwardWithOffset: offset - cacheLen]; + retOffset = [self _seekForwardWithOffset: offset - cacheLength]; [self freeMemory: cache]; cache = NULL; - cacheLen = 0; + cacheLength = 0; - return ret; + return retOffset; } - (off_t)seekToOffsetRelativeToEnd: (off_t)offset { - off_t ret; + off_t retOffset; - ret = [self _seekToOffsetRelativeToEnd: offset]; + retOffset = [self _seekToOffsetRelativeToEnd: offset]; [self freeMemory: cache]; cache = NULL; - cacheLen = 0; + cacheLength = 0; - return ret; + return retOffset; } @end Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -31,12 +31,12 @@ * the _ prefix, you *WILL* break caching and get broken results! */ @interface OFStream: OFObject { char *cache; - char *wBuffer; - size_t cacheLen, wBufferLen; + char *writeBuffer; + size_t cacheLength, writeBufferLength; BOOL buffersWrites; BOOL isBlocking; } #ifdef OF_HAVE_PROPERTIES @@ -51,33 +51,33 @@ - (BOOL)isAtEndOfStream; /** * Reads at most size bytes from the stream into a buffer. * - * \param buf The buffer into which the data is read - * \param size The size of the data that should be read at most. - * The buffer MUST be at least size big! + * \param buffer The buffer into which the data is read + * \param length The length of the data that should be read at most. + * The buffer MUST be at least this big! * \return The number of bytes read */ - (size_t)readNBytes: (size_t)size - intoBuffer: (char*)buf; + intoBuffer: (char*)buffer; /** - * Reads exactly size bytes from the stream into a buffer. Unlike + * Reads exactly length bytes from the stream into a buffer. Unlike * readNBytes:intoBuffer:, this method does not return when less than the - * specified size has been read - instead, it waits until it got exactly size + * specified length has been read - instead, it waits until it got exactly length * bytes. * * WARNING: Only call this when you know that specified amount of data is * available! Otherwise you will get an exception! * - * \param buf The buffer into which the data is read - * \param size The size of the data that should be read. + * \param buffer The buffer into which the data is read + * \param length The length of the data that should be read. * The buffer MUST be EXACTLY this big! */ -- (void)readExactlyNBytes: (size_t)size - intoBuffer: (char*)buf; +- (void)readExactlyNBytes: (size_t)length + intoBuffer: (char*)buffer; /** * Reads a uint8_t from the stream. * * WARNING: Only call this when you know that enough data is available! @@ -152,16 +152,16 @@ * them in an OFDataArray. * * WARNING: Only call this when you know that enough data is available! * Otherwise you will get an exception! * - * \param itemsize The size of each item - * \param nitems The number of iteams to read + * \param itemSize The size of each item + * \param nItems The number of iteams to read * \return An OFDataArray with at nitems items. */ -- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize - andNItems: (size_t)nitems; +- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize + andNItems: (size_t)nItems; /** * \return An OFDataArray with an item size of 1 with all the data of the * stream until the end of the stream is reached. */ @@ -223,16 +223,16 @@ - (void)flushWriteBuffer; /** * Writes from a buffer into the stream. * - * \param buf The buffer from which the data is written to the stream - * \param size The size of the data that should be written + * \param buffer The buffer from which the data is written to the stream + * \param length The length of the data that should be written * \return The number of bytes written */ -- (size_t)writeNBytes: (size_t)size - fromBuffer: (const char*)buf; +- (size_t)writeNBytes: (size_t)length + fromBuffer: (const char*)buffer; /** * Writes a uint8_t into the stream. * * \param int8 A uint8_t @@ -282,48 +282,48 @@ - (void)writeLittleEndianInt64: (uint64_t)int64; /** * Writes from an OFDataArray into the stream. * - * \param dataarray The OFDataArray to write into the stream + * \param dataArray The OFDataArray to write into the stream * \return The number of bytes written */ -- (size_t)writeDataArray: (OFDataArray*)dataarray; +- (size_t)writeDataArray: (OFDataArray*)dataArray; /** * Writes a string into the stream, without the trailing zero. * - * \param str The string from which the data is written to the stream + * \param string The string from which the data is written to the stream * \return The number of bytes written */ -- (size_t)writeString: (OFString*)str; +- (size_t)writeString: (OFString*)string; /** * Writes a string into the stream with a trailing newline. * - * \param str The string from which the data is written to the stream + * \param string The string from which the data is written to the stream * \return The number of bytes written */ -- (size_t)writeLine: (OFString*)str; +- (size_t)writeLine: (OFString*)string; /** * Writes a formatted string into the stream. * - * \param fmt A string used as format + * \param format A string used as format * \return The number of bytes written */ -- (size_t)writeFormat: (OFString*)fmt, ...; +- (size_t)writeFormat: (OFString*)format, ...; /** * Writes a formatted string into the stream. * - * \param fmt A string used as format - * \param args The arguments used in the format string + * \param format A string used as format + * \param arguments The arguments used in the format string * \return The number of bytes written */ -- (size_t)writeFormat: (OFString*)fmt - withArguments: (va_list)args; +- (size_t)writeFormat: (OFString*)format + withArguments: (va_list)arguments; /** * \return The number of bytes still present in the internal cache. */ - (size_t)pendingBytes; Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -59,11 +59,11 @@ } self = [super init]; cache = NULL; - wBuffer = NULL; + writeBuffer = NULL; isBlocking = YES; return self; } @@ -71,19 +71,19 @@ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } -- (size_t)_readNBytes: (size_t)size - intoBuffer: (char*)buf +- (size_t)_readNBytes: (size_t)length + intoBuffer: (char*)buffer { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } -- (size_t)_writeNBytes: (size_t)size - fromBuffer: (const char*)buf +- (size_t)_writeNBytes: (size_t)length + fromBuffer: (const char*)buffer { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } @@ -93,48 +93,48 @@ return NO; return [self _isAtEndOfStream]; } -- (size_t)readNBytes: (size_t)size - intoBuffer: (char*)buf +- (size_t)readNBytes: (size_t)length + intoBuffer: (char*)buffer { if (cache == NULL) - return [self _readNBytes: size - intoBuffer: buf]; + return [self _readNBytes: length + intoBuffer: buffer]; - if (size >= cacheLen) { - size_t ret = cacheLen; - memcpy(buf, cache, cacheLen); + if (length >= cacheLength) { + size_t ret = cacheLength; + memcpy(buffer, cache, cacheLength); [self freeMemory: cache]; cache = NULL; - cacheLen = 0; + cacheLength = 0; return ret; } else { - char *tmp = [self allocMemoryWithSize: cacheLen - size]; - memcpy(tmp, cache + size, cacheLen - size); + char *tmp = [self allocMemoryWithSize: cacheLength - length]; + memcpy(tmp, cache + length, cacheLength - length); - memcpy(buf, cache, size); + memcpy(buffer, cache, length); [self freeMemory: cache]; cache = tmp; - cacheLen -= size; + cacheLength -= length; - return size; + return length; } } -- (void)readExactlyNBytes: (size_t)size - intoBuffer: (char*)buf -{ - size_t len = 0; - - while (len < size) - len += [self readNBytes: size - len - intoBuffer: buf + len]; +- (void)readExactlyNBytes: (size_t)length + intoBuffer: (char*)buffer +{ + size_t readLength = 0; + + while (readLength < length) + readLength += [self readNBytes: length - readLength + intoBuffer: buffer + readLength]; } - (uint8_t)readInt8 { uint8_t ret; @@ -203,25 +203,25 @@ intoBuffer: (char*)&ret]; return of_bswap64_if_be(ret); } -- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize - andNItems: (size_t)nitems +- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize + andNItems: (size_t)nItems { OFDataArray *da; char *tmp; - da = [OFDataArray dataArrayWithItemSize: itemsize]; - tmp = [self allocMemoryForNItems: nitems - withSize: itemsize]; + da = [OFDataArray dataArrayWithItemSize: itemSize]; + tmp = [self allocMemoryForNItems: nItems + withSize: itemSize]; @try { - [self readExactlyNBytes: nitems * itemsize + [self readExactlyNBytes: nItems * itemSize intoBuffer: tmp]; - [da addNItems: nitems + [da addNItems: nItems fromCArray: tmp]; } @finally { [self freeMemory: tmp]; } @@ -228,172 +228,180 @@ return da; } - (OFDataArray*)readDataArrayTillEndOfStream { - OFDataArray *a; - char *buf; + OFDataArray *dataArray; + char *buffer; - a = [OFDataArray dataArrayWithItemSize: 1]; - buf = [self allocMemoryWithSize: of_pagesize]; + dataArray = [OFDataArray dataArrayWithItemSize: 1]; + buffer = [self allocMemoryWithSize: of_pagesize]; @try { while (![self isAtEndOfStream]) { - size_t size; + size_t length; - size = [self readNBytes: of_pagesize - intoBuffer: buf]; - [a addNItems: size - fromCArray: buf]; + length = [self readNBytes: of_pagesize + intoBuffer: buffer]; + [dataArray addNItems: length + fromCArray: buffer]; } } @finally { - [self freeMemory: buf]; + [self freeMemory: buffer]; } - return a; + return dataArray; } - (OFString*)readLine { return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding { - size_t i, len, ret_len; - char *ret_c, *tmp, *tmp2; + size_t i, bufferLength, retLength; + char *retCString, *buffer, *newCache; OFString *ret; /* Look if there's a line or \0 in our cache */ if (cache != NULL) { - for (i = 0; i < cacheLen; i++) { + for (i = 0; i < cacheLength; i++) { if (OF_UNLIKELY(cache[i] == '\n' || cache[i] == '\0')) { - ret_len = i; + retLength = i; if (i > 0 && cache[i - 1] == '\r') - ret_len--; + retLength--; ret = [OFString stringWithCString: cache encoding: encoding - length: ret_len]; + length: retLength]; - tmp = [self allocMemoryWithSize: cacheLen - - i - 1]; - if (tmp != NULL) - memcpy(tmp, cache + i + 1, - cacheLen - i - 1); + newCache = [self + allocMemoryWithSize: cacheLength - i - 1]; + if (newCache != NULL) + memcpy(newCache, cache + i + 1, + cacheLength - i - 1); [self freeMemory: cache]; - cache = tmp; - cacheLen -= i + 1; + cache = newCache; + cacheLength -= i + 1; return ret; } } } /* Read until we get a newline or \0 */ - tmp = [self allocMemoryWithSize: of_pagesize]; + buffer = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { if ([self _isAtEndOfStream]) { if (cache == NULL) return nil; - ret_len = cacheLen; + retLength = cacheLength; - if (ret_len > 0 && cache[ret_len - 1] == '\r') - ret_len--; + if (retLength > 0 && + cache[retLength - 1] == '\r') + retLength--; ret = [OFString stringWithCString: cache encoding: encoding - length: ret_len]; + length: retLength]; [self freeMemory: cache]; cache = NULL; - cacheLen = 0; + cacheLength = 0; return ret; } - len = [self _readNBytes: of_pagesize - intoBuffer: tmp]; + bufferLength = [self _readNBytes: of_pagesize + intoBuffer: buffer]; /* Look if there's a newline or \0 */ - for (i = 0; i < len; i++) { - if (OF_UNLIKELY(tmp[i] == '\n' || - tmp[i] == '\0')) { - ret_len = cacheLen + i; - ret_c = [self - allocMemoryWithSize: ret_len]; + for (i = 0; i < bufferLength; i++) { + if (OF_UNLIKELY(buffer[i] == '\n' || + buffer[i] == '\0')) { + retLength = cacheLength + i; + retCString = [self + allocMemoryWithSize: retLength]; if (cache != NULL) - memcpy(ret_c, cache, cacheLen); - memcpy(ret_c + cacheLen, tmp, i); + memcpy(retCString, cache, + cacheLength); + memcpy(retCString + cacheLength, + buffer, i); - if (ret_len > 0 && - ret_c[ret_len - 1] == '\r') - ret_len--; + if (retLength > 0 && + retCString[retLength - 1] == '\r') + retLength--; @try { + char *rcs = retCString; + size_t rl = retLength; + ret = [OFString - stringWithCString: ret_c + stringWithCString: rcs encoding: encoding - length: ret_len]; + length: rl]; } @catch (id e) { /* * Append data to cache to * prevent loss of data due to * wrong encoding. */ cache = [self resizeMemory: cache - toSize: cacheLen + - len]; + toSize: cacheLength + + bufferLength]; if (cache != NULL) - memcpy(cache + cacheLen, - tmp, len); + memcpy(cache + + cacheLength, buffer, + bufferLength); - cacheLen += len; + cacheLength += bufferLength; @throw e; } @finally { - [self freeMemory: ret_c]; + [self freeMemory: retCString]; } - tmp2 = [self - allocMemoryWithSize: len - i - 1]; - if (tmp2 != NULL) - memcpy(tmp2, tmp + i + 1, - len - i - 1); + newCache = [self allocMemoryWithSize: + bufferLength - i - 1]; + if (newCache != NULL) + memcpy(newCache, buffer + i + 1, + bufferLength - i - 1); [self freeMemory: cache]; - cache = tmp2; - cacheLen = len - i - 1; + cache = newCache; + cacheLength = bufferLength - i - 1; return ret; } } /* There was no newline or \0 */ cache = [self resizeMemory: cache - toSize: cacheLen + len]; + toSize: cacheLength + bufferLength]; /* * It's possible that cacheLen + len is 0 and thus * cache was set to NULL by resizeMemory:toSize:. */ if (cache != NULL) - memcpy(cache + cacheLen, tmp, len); + memcpy(cache + cacheLength, buffer, + bufferLength); - cacheLen += len; + cacheLength += bufferLength; } } @finally { - [self freeMemory: tmp]; + [self freeMemory: buffer]; } /* Get rid of a warning, never reached anyway */ assert(0); } @@ -405,137 +413,145 @@ } - (OFString*)readTillDelimiter: (OFString*)delimiter withEncoding: (of_string_encoding_t)encoding { - const char *delim; - size_t i, j, delim_len, len, ret_len; - char *ret_c, *tmp, *tmp2; + const char *delimiterCString; + size_t i, j, delimiterLength, bufferLength, retLength; + char *retCString, *buffer, *newCache; OFString *ret; /* FIXME: Convert delimiter to specified charset */ - delim = [delimiter cString]; - delim_len = [delimiter cStringLength]; + delimiterCString = [delimiter cString]; + delimiterLength = [delimiter cStringLength]; j = 0; - if (delim_len == 0) + if (delimiterLength == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; /* Look if there's something in our cache */ if (cache != NULL) { - for (i = 0; i < cacheLen; i++) { - if (cache[i] != delim[j++]) + for (i = 0; i < cacheLength; i++) { + if (cache[i] != delimiterCString[j++]) j = 0; - if (j == delim_len || cache[i] == '\0') { + if (j == delimiterLength || cache[i] == '\0') { if (cache[i] == '\0') - delim_len = 1; - - ret = [OFString stringWithCString: cache - encoding: encoding - length: i + 1 - - delim_len]; - - tmp = [self allocMemoryWithSize: cacheLen - i - - 1]; - if (tmp != NULL) - memcpy(tmp, cache + i + 1, - cacheLen - i - 1); + delimiterLength = 1; + + ret = [OFString + stringWithCString: cache + encoding: encoding + length: i + 1 - delimiterLength]; + + newCache = [self allocMemoryWithSize: + cacheLength - i - 1]; + if (newCache != NULL) + memcpy(newCache, cache + i + 1, + cacheLength - i - 1); [self freeMemory: cache]; - cache = tmp; - cacheLen -= i + 1; + cache = newCache; + cacheLength -= i + 1; return ret; } } } /* Read until we get the delimiter or \0 */ - tmp = [self allocMemoryWithSize: of_pagesize]; + buffer = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { if ([self _isAtEndOfStream]) { if (cache == NULL) return nil; ret = [OFString stringWithCString: cache encoding: encoding - length: cacheLen]; + length: cacheLength]; [self freeMemory: cache]; cache = NULL; - cacheLen = 0; + cacheLength = 0; return ret; } - len = [self _readNBytes: of_pagesize - intoBuffer: tmp]; + bufferLength = [self _readNBytes: of_pagesize + intoBuffer: buffer]; /* Look if there's the delimiter or \0 */ - for (i = 0; i < len; i++) { - if (tmp[i] != delim[j++]) + for (i = 0; i < bufferLength; i++) { + if (buffer[i] != delimiterCString[j++]) j = 0; - if (j == delim_len || tmp[i] == '\0') { - if (tmp[i] == '\0') - delim_len = 1; + if (j == delimiterLength || buffer[i] == '\0') { + if (buffer[i] == '\0') + delimiterLength = 1; - ret_len = cacheLen + i + 1 - delim_len; - ret_c = [self - allocMemoryWithSize: ret_len]; + retLength = cacheLength + i + 1 - + delimiterLength; + retCString = [self + allocMemoryWithSize: retLength]; if (cache != NULL && - cacheLen <= ret_len) - memcpy(ret_c, cache, cacheLen); + cacheLength <= retLength) + memcpy(retCString, cache, + cacheLength); else if (cache != NULL) - memcpy(ret_c, cache, ret_len); - if (i >= delim_len) - memcpy(ret_c + cacheLen, tmp, - i + 1 - delim_len); + memcpy(retCString, cache, + retLength); + if (i >= delimiterLength) + memcpy(retCString + cacheLength, + buffer, i + 1 - + delimiterLength); @try { - ret = [OFString - stringWithCString: ret_c - encoding: encoding - length: ret_len]; - } @finally { - [self freeMemory: ret_c]; - } - - tmp2 = [self - allocMemoryWithSize: len - i - 1]; - if (tmp2 != NULL) - memcpy(tmp2, tmp + i + 1, - len - i - 1); - - [self freeMemory: cache]; - cache = tmp2; - cacheLen = len - i - 1; + char *rcs = retCString; + size_t rl = retLength; + + ret = [OFString + stringWithCString: rcs + encoding: encoding + length: rl]; + } @finally { + [self freeMemory: retCString]; + } + + newCache = [self allocMemoryWithSize: + bufferLength - i - 1]; + if (newCache != NULL) + memcpy(newCache, buffer + i + 1, + bufferLength - i - 1); + + [self freeMemory: cache]; + cache = newCache; + cacheLength = bufferLength - i - 1; return ret; } } /* Neither the delimiter nor \0 was found */ cache = [self resizeMemory: cache - toSize: cacheLen + len]; + toSize: cacheLength + bufferLength]; /* * It's possible that cacheLen + len is 0 and thus * cache was set to NULL by resizeMemory:toSize:. */ if (cache != NULL) - memcpy(cache + cacheLen, tmp, len); + memcpy(cache + cacheLength, buffer, + bufferLength); - cacheLen += len; + cacheLength += bufferLength; } } @finally { - [self freeMemory: tmp]; + [self freeMemory: buffer]; } /* Get rid of a warning, never reached anyway */ assert(0); } @@ -550,34 +566,34 @@ buffersWrites = enable; } - (void)flushWriteBuffer { - if (wBuffer == NULL) + if (writeBuffer == NULL) return; - [self _writeNBytes: wBufferLen - fromBuffer: wBuffer]; + [self _writeNBytes: writeBufferLength + fromBuffer: writeBuffer]; - [self freeMemory: wBuffer]; - wBuffer = NULL; - wBufferLen = 0; + [self freeMemory: writeBuffer]; + writeBuffer = NULL; + writeBufferLength = 0; } -- (size_t)writeNBytes: (size_t)size - fromBuffer: (const char*)buf +- (size_t)writeNBytes: (size_t)length + fromBuffer: (const char*)buffer { if (!buffersWrites) - return [self _writeNBytes: size - fromBuffer: buf]; + return [self _writeNBytes: length + fromBuffer: buffer]; else { - wBuffer = [self resizeMemory: wBuffer - toSize: wBufferLen + size]; - memcpy(wBuffer + wBufferLen, buf, size); - wBufferLen += size; + writeBuffer = [self resizeMemory: writeBuffer + toSize: writeBufferLength + length]; + memcpy(writeBuffer + writeBufferLength, buffer, length); + writeBufferLength += length; - return size; + return length; } } - (void)writeInt8: (uint8_t)int8 { @@ -631,82 +647,83 @@ [self writeNBytes: 8 fromBuffer: (char*)&int64]; } -- (size_t)writeDataArray: (OFDataArray*)dataarray -{ - return [self writeNBytes: [dataarray count] * [dataarray itemSize] - fromBuffer: [dataarray cArray]]; -} - -- (size_t)writeString: (OFString*)str -{ - return [self writeNBytes: [str cStringLength] - fromBuffer: [str cString]]; -} - -- (size_t)writeLine: (OFString*)str -{ - size_t ret, len = [str cStringLength]; - char *buf; - - buf = [self allocMemoryWithSize: len + 1]; - - @try { - memcpy(buf, [str cString], len); - buf[len] = '\n'; - - ret = [self writeNBytes: len + 1 - fromBuffer: buf]; - } @finally { - [self freeMemory: buf]; - } - - return ret; -} - -- (size_t)writeFormat: (OFString*)fmt, ... -{ - va_list args; - 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 -{ - char *t; - int len; - - if (fmt == nil) - @throw [OFInvalidArgumentException newWithClass: isa - selector: _cmd]; - - if ((len = of_vasprintf(&t, [fmt cString], args)) == -1) - @throw [OFInvalidFormatException newWithClass: isa]; - - @try { - return [self writeNBytes: len - fromBuffer: t]; - } @finally { - free(t); +- (size_t)writeDataArray: (OFDataArray*)dataArray +{ + return [self writeNBytes: [dataArray count] * [dataArray itemSize] + fromBuffer: [dataArray cArray]]; +} + +- (size_t)writeString: (OFString*)string +{ + return [self writeNBytes: [string cStringLength] + fromBuffer: [string cString]]; +} + +- (size_t)writeLine: (OFString*)string +{ + size_t retLength, stringLength = [string cStringLength]; + char *buffer; + + buffer = [self allocMemoryWithSize: stringLength + 1]; + + @try { + memcpy(buffer, [string cString], stringLength); + buffer[stringLength] = '\n'; + + retLength = [self writeNBytes: stringLength + 1 + fromBuffer: buffer]; + } @finally { + [self freeMemory: buffer]; + } + + return retLength; +} + +- (size_t)writeFormat: (OFString*)format, ... +{ + va_list arguments; + size_t ret; + + va_start(arguments, format); + ret = [self writeFormat: format + withArguments: arguments]; + va_end(arguments); + + return ret; +} + +- (size_t)writeFormat: (OFString*)format + withArguments: (va_list)arguments +{ + char *cString; + int length; + + if (format == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + if ((length = of_vasprintf(&cString, [format cString], + arguments)) == -1) + @throw [OFInvalidFormatException newWithClass: isa]; + + @try { + return [self writeNBytes: length + fromBuffer: cString]; + } @finally { + free(cString); } /* Get rid of a warning, never reached anyway */ assert(0); } - (size_t)pendingBytes { - return cacheLen; + return cacheLength; } - (BOOL)isBlocking { return isBlocking; Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -27,13 +27,13 @@ * \brief A class which provides functions to create and use stream sockets. */ @interface OFStreamSocket: OFStream { int sock; - BOOL eos; + BOOL isAtEndOfStream; } /** * \return A new autoreleased OFTCPSocket */ + socket; @end Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -60,78 +60,78 @@ return [[[self alloc] init] autorelease]; } - (BOOL)_isAtEndOfStream { - return eos; + return isAtEndOfStream; } -- (size_t)_readNBytes: (size_t)size - intoBuffer: (char*)buf +- (size_t)_readNBytes: (size_t)length + intoBuffer: (char*)buffer { - ssize_t ret; + ssize_t retLength; if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa socket: self]; - if (eos) { + if (isAtEndOfStream) { OFReadFailedException *e; e = [OFReadFailedException newWithClass: isa stream: self - requestedSize: size]; + requestedLength: length]; #ifndef _WIN32 e->errNo = ENOTCONN; #else e->errNo = WSAENOTCONN; #endif @throw e; } - if ((ret = recv(sock, buf, size, 0)) < 0) + if ((retLength = recv(sock, buffer, length, 0)) < 0) @throw [OFReadFailedException newWithClass: isa stream: self - requestedSize: size]; - - if (ret == 0) - eos = YES; - - return ret; -} - -- (size_t)_writeNBytes: (size_t)size - fromBuffer: (const char*)buf -{ - ssize_t ret; + requestedLength: length]; + + if (retLength == 0) + isAtEndOfStream = YES; + + return retLength; +} + +- (size_t)_writeNBytes: (size_t)length + fromBuffer: (const char*)buffer +{ + ssize_t retLength; if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa socket: self]; - if (eos) { + if (isAtEndOfStream) { OFWriteFailedException *e; e = [OFWriteFailedException newWithClass: isa stream: self - requestedSize: size]; + requestedLength: length]; #ifndef _WIN32 e->errNo = ENOTCONN; #else e->errNo = WSAENOTCONN; #endif @throw e; } - if ((ret = send(sock, buf, size, 0)) == -1) + if ((retLength = send(sock, buffer, length, 0)) == -1) @throw [OFWriteFailedException newWithClass: isa stream: self - requestedSize: size]; + requestedLength: length]; - return ret; + return retLength; } #ifdef _WIN32 - (void)setBlocking: (BOOL)enable { @@ -156,11 +156,11 @@ socket: self]; close(sock); sock = INVALID_SOCKET; - eos = NO; + isAtEndOfStream = NO; } - (void)dealloc { if (sock != INVALID_SOCKET) Index: src/exceptions/OFReadFailedException.m ================================================================== --- src/exceptions/OFReadFailedException.m +++ src/exceptions/OFReadFailedException.m @@ -26,11 +26,11 @@ { if (description != nil) return description; description = [[OFString alloc] initWithFormat: - @"Failed to read %zu bytes in class %@! " ERRFMT, requestedSize, + @"Failed to read %zu bytes in class %@! " ERRFMT, requestedLength, inClass, ERRPARAM]; return description; } @end Index: src/exceptions/OFReadOrWriteFailedException.h ================================================================== --- src/exceptions/OFReadOrWriteFailedException.h +++ src/exceptions/OFReadOrWriteFailedException.h @@ -22,53 +22,55 @@ * \brief An exception indicating a read or write to a stream failed. */ @interface OFReadOrWriteFailedException: OFException { OFStream *stream; - size_t requestedSize; + size_t requestedLength; @public int errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, nonatomic) OFStream *stream; -@property (readonly) size_t requestedSize; +@property (readonly) size_t requestedLength; @property (readonly) int errNo; #endif /** * \param class_ The class of the object which caused the exception * \param stream The stream which caused the read or write failed exception - * \param size The requested size of the data that couldn't be read / written + * \param length The requested length of the data that couldn't be read / + * written * \return A new open file failed exception */ -+ newWithClass: (Class)class_ - stream: (OFStream*)stream - requestedSize: (size_t)size; ++ newWithClass: (Class)class_ + stream: (OFStream*)stream + requestedLength: (size_t)length; /** * Initializes an already allocated read or write failed exception. * * \param class_ The class of the object which caused the exception * \param stream The stream which caused the read or write failed exception - * \param size The requested size of the data that couldn't be read / written + * \param length The requested length of the data that couldn't be read / + * written * \return A new open file failed exception */ -- initWithClass: (Class)class_ - stream: (OFStream*)stream - requestedSize: (size_t)size; +- initWithClass: (Class)class_ + stream: (OFStream*)stream + requestedLength: (size_t)length; /** * \return The stream which caused the read or write failed exception */ - (OFStream*)stream; /** - * \return The requested size of the data that couldn't be read / written + * \return The requested length of the data that couldn't be read / written */ -- (size_t)requestedSize; +- (size_t)requestedLength; /** * \return The errno from when the exception was created */ - (int)errNo; @end Index: src/exceptions/OFReadOrWriteFailedException.m ================================================================== --- src/exceptions/OFReadOrWriteFailedException.m +++ src/exceptions/OFReadOrWriteFailedException.m @@ -23,17 +23,17 @@ #import "OFNotImplementedException.h" #import "common.h" @implementation OFReadOrWriteFailedException -+ newWithClass: (Class)class_ - stream: (OFStream*)stream - requestedSize: (size_t)size ++ newWithClass: (Class)class_ + stream: (OFStream*)stream + requestedLength: (size_t)length { return [[self alloc] initWithClass: class_ stream: stream - requestedSize: size]; + requestedLength: length]; } - initWithClass: (Class)class_ { Class c = isa; @@ -40,19 +40,19 @@ [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } -- initWithClass: (Class)class_ - stream: (OFStream*)stream_ - requestedSize: (size_t)size +- initWithClass: (Class)class_ + stream: (OFStream*)stream_ + requestedLength: (size_t)length { self = [super initWithClass: class_]; @try { stream = [stream_ retain]; - requestedSize = size; + requestedLength = length; if ([class_ isSubclassOfClass: [OFStreamSocket class]]) errNo = GET_SOCK_ERRNO; else errNo = GET_ERRNO; @@ -73,15 +73,15 @@ - (OFStream*)stream { return stream; } -- (size_t)requestedSize +- (size_t)requestedLength { - return requestedSize; + return requestedLength; } - (int)errNo { return errNo; } @end Index: src/exceptions/OFWriteFailedException.m ================================================================== --- src/exceptions/OFWriteFailedException.m +++ src/exceptions/OFWriteFailedException.m @@ -26,11 +26,11 @@ { if (description != nil) return description; description = [[OFString alloc] initWithFormat: - @"Failed to write %zu bytes in class %@! " ERRFMT, requestedSize, + @"Failed to write %zu bytes in class %@! " ERRFMT, requestedLength, inClass, ERRPARAM]; return description; } @end