ObjFW  Diff

Differences From Artifact [8d9bbeeba6]:

To Artifact [84af7e353c]:

  • File src/OFStdIOStream.m — part of check-in [4e59d2692f] at 2014-04-26 00:40:17 on branch trunk — Fix a few issues on LLP64 and Win64

    LLP64 was mostly fast enumeration using an unsigned long for the state,
    which can't store a pointer or a size_t on LLP64. This is now solved by
    either throwing an OFOutOfRangeException if the value of the size_t is
    bigger than ULONG_MAX or storing the pointer in the extra field (copied
    using memcpy, as it's an array of unsigned long, which again would be
    too small to store a pointer).

    Win64 was mostly Microsoft not being able to decide whether a length is
    a size_t, a DWORD, an int or an unsigned int (thus the different types
    in places that seem to be almost the same). But since that would not be
    confusing enough, a file descriptor is an int if it's for a file, but a
    long long if it is for a socket. But of course, for ReadFile and friends
    it's a DWORD instead of an int then. (user: js, size: 3662) [annotate] [blame] [check-ins using]


18
19
20
21
22
23
24

25
26
27
28
29
30
31

#include <unistd.h>

#import "OFStdIOStream.h"
#import "OFDate.h"
#import "OFApplication.h"


#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "autorelease.h"
#import "macros.h"

OFStdIOStream *of_stdin = nil;







>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include <unistd.h>

#import "OFStdIOStream.h"
#import "OFDate.h"
#import "OFApplication.h"

#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "autorelease.h"
#import "macros.h"

OFStdIOStream *of_stdin = nil;
90
91
92
93
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
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{
	ssize_t ret;


	if (_fd == -1 || _atEndOfStream ||
	    (ret = read(_fd, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];










	if (ret == 0)
		_atEndOfStream = true;

	return ret;
}

- (void)lowlevelWriteBuffer: (const void*)buffer
		     length: (size_t)length
{

	if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];









}

- (int)fileDescriptorForReading
{
	return _fd;
}








>




>
>
>
>
>
>
>
>
>










>



>
>
>
>
>
>
>
>
>







91
92
93
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
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{
	ssize_t ret;

#ifndef _WIN32
	if (_fd == -1 || _atEndOfStream ||
	    (ret = read(_fd, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];
#else
	if (length > UINT_MAX)
		@throw [OFOutOfRangeException exception];

	if (_fd == -1 || _atEndOfStream ||
	    (ret = read(_fd, buffer, (unsigned int)length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];
#endif

	if (ret == 0)
		_atEndOfStream = true;

	return ret;
}

- (void)lowlevelWriteBuffer: (const void*)buffer
		     length: (size_t)length
{
#ifndef _WIN32
	if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];
#else
	if (length > UINT_MAX)
		@throw [OFOutOfRangeException exception];

	if (_fd == -1 || _atEndOfStream ||
	    write(_fd, buffer, (unsigned int)length) < length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];
#endif
}

- (int)fileDescriptorForReading
{
	return _fd;
}