Differences From Artifact [cecae3f90d]:
- File src/OFStdIOStream.m — part of check-in [d31ec806ef] at 2017-05-27 10:33:09 on branch trunk — Add unistd.h wrapper to make things less horrible (user: js, size: 4592) [annotate] [blame] [check-ins using]
To Artifact [b0cc705195]:
- File
src/OFStdIOStream.m
— part of check-in
[614c6678e8]
at
2017-05-27 14:45:24
on branch trunk
— OFStdIOStream: Use AmigaDOS directly on MorphOS
This is necessary for using -noixemul. (user: js, size: 5341) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #ifdef OF_WINDOWS # include "OFStdIOStream_Win32Console.h" #endif #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" /* References for static linking */ #ifdef OF_WINDOWS void _reference_to_OFStdIOStream_Win32Console(void) { [OFStdIOStream_Win32Console class]; | > > > > > > > > > > > > > > > > > > > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #ifdef OF_WINDOWS # include "OFStdIOStream_Win32Console.h" #endif #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #ifdef OF_MORPHOS # define BOOL EXEC_BOOL # include <exec/execbase.h> # include <proto/dos.h> # 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) { [OFStdIOStream_Win32Console class]; |
︙ | ︙ | |||
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | objc_autoreleasePoolPop(pool); } @implementation OFStdIOStream #ifndef OF_WINDOWS + (void)load { of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: 0]; of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1]; of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2]; } #endif - init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super init]; _fd = fd; return self; } - (bool)lowlevelIsAtEndOfStream { | > > > > > > | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | objc_autoreleasePoolPop(pool); } @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 { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super init]; _fd = fd; return self; } - (bool)lowlevelIsAtEndOfStream { if (_fd == INVALID_FD) return true; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_fd == INVALID_FD || _atEndOfStream) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; #ifndef OF_WINDOWS if ((ret = read(_fd, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length |
︙ | ︙ | |||
136 137 138 139 140 141 142 | return ret; } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { | | | > > | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | return ret; } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_fd == INVALID_FD || _atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; #ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (write(_fd, (void *)buffer, length) != (ssize_t)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if (write(_fd, buffer, (int)length) != (int)length) @throw [OFWriteFailedException exceptionWithObject: self 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 != INVALID_FD) close(_fd); _fd = INVALID_FD; [super close]; } - autorelease { return self; |
︙ | ︙ |