@@ -190,6 +190,17 @@ FileIOResult File::read_unlocked(void *data, size_t len) {
190
190
191
191
prev_op = FileOp::READ;
192
192
193
+ if (bufmode == _IONBF) { // unbuffered.
194
+ return read_unlocked_nbf (static_cast <uint8_t *>(data), len);
195
+ } else if (bufmode == _IOFBF) { // fully buffered
196
+ return read_unlocked_fbf (static_cast <uint8_t *>(data), len);
197
+ } else /* if (bufmode == _IOLBF) */ { // line buffered
198
+ // There is no line buffered mode for read. Use fully buffer instead.
199
+ return read_unlocked_fbf (static_cast <uint8_t *>(data), len);
200
+ }
201
+ }
202
+
203
+ FileIOResult File::read_unlocked_fbf (uint8_t *data, size_t len) {
193
204
cpp::span<uint8_t > bufref (static_cast <uint8_t *>(buf), bufsize);
194
205
cpp::span<uint8_t > dataref (static_cast <uint8_t *>(data), len);
195
206
@@ -245,6 +256,18 @@ FileIOResult File::read_unlocked(void *data, size_t len) {
245
256
return {transfer_size + available_data, result.error };
246
257
}
247
258
259
+ FileIOResult File::read_unlocked_nbf (uint8_t *data, size_t len) {
260
+ auto result = platform_read (this , data, len);
261
+
262
+ if (result.has_error () || result < len) {
263
+ if (!result.has_error ())
264
+ eof = true ;
265
+ else
266
+ err = true ;
267
+ }
268
+ return result;
269
+ }
270
+
248
271
int File::ungetc_unlocked (int c) {
249
272
// There is no meaning to unget if:
250
273
// 1. You are trying to push back EOF.
0 commit comments