@@ -531,13 +531,12 @@ #if !defined(_WIN32) && !defined(_PSP) if (!override) { struct stat s; - if (fstat(sourceFile->fileDescriptor, &s) == 0) - fchmod(destinationFile->fileDescriptor, - s.st_mode); + if (fstat(sourceFile->fd, &s) == 0) + fchmod(destinationFile->fd, s.st_mode); } #else (void)override; #endif } @finally { @@ -659,11 +658,11 @@ OF_STRING_ENCODING_NATIVE])) == -1) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if ((fileDescriptor = open([path cStringWithEncoding: + if ((fd = open([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) @throw [OFOpenFileFailedException exceptionWithClass: [self class] path: path mode: mode]; @@ -675,22 +674,22 @@ } return self; } -- initWithFileDescriptor: (int)fileDescriptor_ +- initWithFileDescriptor: (int)fileDescriptor { self = [super init]; - fileDescriptor = fileDescriptor_; + fd = fileDescriptor; return self; } - (BOOL)_isAtEndOfStream { - if (fileDescriptor == -1) + if (fd == -1) return YES; return atEndOfStream; } @@ -697,12 +696,11 @@ - (size_t)_readIntoBuffer: (void*)buffer length: (size_t)length { ssize_t ret; - if (fileDescriptor == -1 || atEndOfStream || - (ret = read(fileDescriptor, buffer, length)) < 0) + if (fd == -1 || atEndOfStream || (ret = read(fd, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; if (ret == 0) @@ -712,20 +710,19 @@ } - (void)_writeBuffer: (const void*)buffer length: (size_t)length { - if (fileDescriptor == -1 || atEndOfStream || - write(fileDescriptor, buffer, length) < length) + if (fd == -1 || atEndOfStream || write(fd, buffer, length) < length) @throw [OFWriteFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; } - (void)_seekToOffset: (off_t)offset { - if (lseek(fileDescriptor, offset, SEEK_SET) == -1) + if (lseek(fd, offset, SEEK_SET) == -1) @throw [OFSeekFailedException exceptionWithClass: [self class] stream: self offset: offset whence: SEEK_SET]; } @@ -732,11 +729,11 @@ - (off_t)_seekForwardWithOffset: (off_t)offset { off_t ret; - if ((ret = lseek(fileDescriptor, offset, SEEK_CUR)) == -1) + if ((ret = lseek(fd, offset, SEEK_CUR)) == -1) @throw [OFSeekFailedException exceptionWithClass: [self class] stream: self offset: offset whence: SEEK_CUR]; @@ -745,36 +742,41 @@ - (off_t)_seekToOffsetRelativeToEnd: (off_t)offset { off_t ret; - if ((ret = lseek(fileDescriptor, offset, SEEK_END)) == -1) + if ((ret = lseek(fd, offset, SEEK_END)) == -1) @throw [OFSeekFailedException exceptionWithClass: [self class] stream: self offset: offset whence: SEEK_END]; return ret; } -- (int)fileDescriptor +- (int)fileDescriptorForReading +{ + return fd; +} + +- (int)fileDescriptorForWriting { - return fileDescriptor; + return fd; } - (void)close { - if (fileDescriptor != -1) - close(fileDescriptor); + if (fd != -1) + close(fd); - fileDescriptor = -1; + fd = -1; } - (void)dealloc { - if (closable && fileDescriptor != -1) - close(fileDescriptor); + if (closable && fd != -1) + close(fd); [super dealloc]; } @end