Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -36,10 +36,29 @@ #endif #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" + +#ifdef OF_MORPHOS +# define BOOL EXEC_BOOL +# include +# include +# undef BOOL + +# define INVALID_FD 0 +# define getpid() ((int)SysBase->ThisTask) +# define read(fd, buf, len) Read(fd, buf, len) +# define write(fd, buf, len) Write(fd, buf, len) +# define close(fd) Close(fd) + +extern struct ExecBase *SysBase; +#endif + +#ifndef INVALID_FD +# define INVALID_FD -1 +#endif /* References for static linking */ #ifdef OF_WINDOWS void _reference_to_OFStdIOStream_Win32Console(void) @@ -77,13 +96,19 @@ @implementation OFStdIOStream #ifndef OF_WINDOWS + (void)load { +# ifndef OF_MORPHOS of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: 0]; of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1]; of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2]; +# else + of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: Input()]; + of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: Output()]; + of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: Output()]; +# endif } #endif - init { @@ -99,11 +124,11 @@ return self; } - (bool)lowlevelIsAtEndOfStream { - if (_fd == -1) + if (_fd == INVALID_FD) return true; return _atEndOfStream; } @@ -110,11 +135,11 @@ - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; - if (_fd == -1 || _atEndOfStream) + if (_fd == INVALID_FD || _atEndOfStream) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; #ifndef OF_WINDOWS if ((ret = read(_fd, buffer, length)) < 0) @@ -138,19 +163,19 @@ } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { - if (_fd == -1 || _atEndOfStream) + if (_fd == INVALID_FD || _atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; #ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; - if (write(_fd, buffer, length) != (ssize_t)length) + if (write(_fd, (void *)buffer, length) != (ssize_t)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #else if (length > INT_MAX) @@ -161,26 +186,28 @@ requestedLength: length errNo: errno]; #endif } +#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) - (int)fileDescriptorForReading { return _fd; } - (int)fileDescriptorForWriting { return _fd; } +#endif - (void)close { - if (_fd != -1) + if (_fd != INVALID_FD) close(_fd); - _fd = -1; + _fd = INVALID_FD; [super close]; } - autorelease