Differences From Artifact [ac607c5f45]:
- File src/OFStdIOStream.m — part of check-in [3cba61d694] at 2017-06-03 16:58:46 on branch trunk — Make sockets work on MorphOS + libnix (user: js, size: 7094) [annotate] [blame] [check-ins using]
To Artifact [87d19ba681]:
- File
src/OFStdIOStream.m
— part of check-in
[c9621825fc]
at
2017-06-04 18:48:03
on branch trunk
— Treat MorphOS + ixemul as a separate platform
This reduces the ifdef hell and makes much more sense, as with ixemul,
no native calls are allowed. (user: js, size: 6784) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
35 36 37 38 39 40 41 | # include "OFStdIOStream_Win32Console.h" #endif #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" | | | | 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 67 68 | # include "OFStdIOStream_Win32Console.h" #endif #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #ifdef OF_MORPHOS # define BOOL EXEC_BOOL # include <proto/exec.h> # undef BOOL #endif /* References for static linking */ #ifdef OF_WINDOWS void _reference_to_OFStdIOStream_Win32Console(void) { [OFStdIOStream_Win32Console class]; } #endif OFStdIOStream *of_stdin = nil; OFStdIOStream *of_stdout = nil; OFStdIOStream *of_stderr = nil; #ifdef OF_MORPHOS OF_DESTRUCTOR() { [of_stdin dealloc]; [of_stdout dealloc]; [of_stderr dealloc]; } #endif |
︙ | ︙ | |||
90 91 92 93 94 95 96 | objc_autoreleasePoolPop(pool); } @implementation OFStdIOStream #ifndef OF_WINDOWS + (void)load { | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 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 BPTR input = Input(), output = Output(); BPTR error = ((struct Process *)FindTask(NULL))->pr_CES; bool inputClosable = false, outputClosable = false, |
︙ | ︙ | |||
130 131 132 133 134 135 136 | #endif - init { OF_INVALID_INIT_METHOD } | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | #endif - init { OF_INVALID_INIT_METHOD } #ifndef OF_MORPHOS - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super init]; _fd = fd; return self; |
︙ | ︙ | |||
161 162 163 164 165 166 167 | [self close]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { | | | | 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 | [self close]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { #ifndef OF_MORPHOS if (_fd == -1) return true; #else if (_handle == 0) return true; #endif return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; #ifndef OF_MORPHOS if (_fd == -1 || _atEndOfStream) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; # ifndef OF_WINDOWS if ((ret = read(_fd, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self |
︙ | ︙ | |||
218 219 220 221 222 223 224 | return ret; } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { | | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | return ret; } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #ifndef OF_MORPHOS if (_fd == -1 || _atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; # ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
254 255 256 257 258 259 260 | if (Write(_handle, (void *)buffer, length) != (LONG)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; #endif } | | | | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | if (Write(_handle, (void *)buffer, length) != (LONG)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; #endif } #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) - (int)fileDescriptorForReading { return _fd; } - (int)fileDescriptorForWriting { return _fd; } #endif - (void)close { #ifndef OF_MORPHOS if (_fd != -1) close(_fd); _fd = -1; #else if (_closable && _handle != 0) Close(_handle); |
︙ | ︙ | |||
304 305 306 307 308 309 310 | - (unsigned int)retainCount { return OF_RETAIN_COUNT_MAX; } - (int)columns { | | < | < | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | - (unsigned int)retainCount { return OF_RETAIN_COUNT_MAX; } - (int)columns { #if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_MORPHOS) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; return ws.ws_col; #else return -1; #endif } - (int)rows { #if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_MORPHOS) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; return ws.ws_row; #else return -1; #endif } @end |