ObjFW  Check-in [b13a0f08e7]

Overview
Comment:Better handling of closed and ended files in OFFile.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b13a0f08e78b6f4e85070dda59b1cacd65ded3ab519d77401ac5a841d2fbb58b
User & Date: js on 2009-04-22 22:17:04
Other Links: manifest | tags
Context
2009-04-22
22:37
Throw exception if the key was not found in the OFDictionary. check-in: 36d50170c9 user: js tags: trunk
22:17
Better handling of closed and ended files in OFFile. check-in: b13a0f08e7 user: js tags: trunk
17:59
Get socket error in OFReadOrWriteFailedException if caused by a socket.
This only affects Win32.
check-in: d06376b200 user: js tags: trunk
Changes

Modified src/OFFile.m from [164c881033] to [3e41bb8976].

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
	}

	return self;
}

- free
{

	fclose(fp);

	return [super free];
}

- (BOOL)atEndOfFile
{



	return (feof(fp) == 0 ? NO : YES);
}

- (size_t)readNItems: (size_t)nitems
	      ofSize: (size_t)size
	  intoBuffer: (char*)buf
{
	size_t ret;


	if ((ret = fread(buf, size, nitems, fp)) == 0 && !feof(fp))

		@throw [OFReadFailedException newWithClass: isa
						   andSize: size
						 andNItems: nitems];

	return ret;
}








>
|






>
>
>









>
|
>







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
	}

	return self;
}

- free
{
	if (fp != NULL)
		fclose(fp);

	return [super free];
}

- (BOOL)atEndOfFile
{
	if (fp == NULL)
		return YES;

	return (feof(fp) == 0 ? NO : YES);
}

- (size_t)readNItems: (size_t)nitems
	      ofSize: (size_t)size
	  intoBuffer: (char*)buf
{
	size_t ret;

	if (fp == NULL || feof(fp) ||
	    ((ret = fread(buf, size, nitems, fp)) == 0 &&
	    size != 0 && nitems != 0 && !feof(fp)))
		@throw [OFReadFailedException newWithClass: isa
						   andSize: size
						 andNItems: nitems];

	return ret;
}

131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146

- (size_t)writeNItems: (size_t)nitems
	       ofSize: (size_t)size
	   fromBuffer: (const char*)buf
{
	size_t ret;


	if ((ret = fwrite(buf, size, nitems, fp)) == 0 &&
	    size != 0 && nitems != 0)
		@throw [OFWriteFailedException newWithClass: isa
						    andSize: size
						  andNItems: nitems];

	return ret;
}








>
|
|







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

- (size_t)writeNItems: (size_t)nitems
	       ofSize: (size_t)size
	   fromBuffer: (const char*)buf
{
	size_t ret;

	if (fp == NULL || feof(fp) ||
	    ((ret = fwrite(buf, size, nitems, fp)) < nitems &&
	    size != 0 && nitems != 0))
		@throw [OFWriteFailedException newWithClass: isa
						    andSize: size
						  andNItems: nitems];

	return ret;
}