summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fread.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-09 21:17:12 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-09 21:17:12 +0100
commitb5cd18739a64c8d923a55b61c89ae3900faafd84 (patch)
treed192f7b25257ae9a8a4760c68f5314dcbc0d9b91 /lib/libc/stdio/fread.c
parent119aed5bc787ccbf23d2f151759ec1f3a80977e1 (diff)
Fix include paths and formatting inconsistencies
Diffstat (limited to 'lib/libc/stdio/fread.c')
-rw-r--r--lib/libc/stdio/fread.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c
index a27b64c4..fb4ca3f6 100644
--- a/lib/libc/stdio/fread.c
+++ b/lib/libc/stdio/fread.c
@@ -1,8 +1,10 @@
-#include <io.h>
-#include <unistd.h>
-#include <string.h>
-#include <atomic.h>
-#include <stdio.h>
+#include "__stdio.h" // for _IO_EOF, _IO_ERR
+
+#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK
+#include <libc.h> // for __IMPL
+#include <stdio.h> // for fread, BUFSIZ, FILE
+#include <string.h> // for memcpy
+#include <unistd.h> // for size_t, read, ssize_t
char __stdin_buffer[BUFSIZ];
@@ -16,35 +18,38 @@ size_t fread(void *restrict ptr, size_t size, size_t nitems,
size_t bytes_read = 0;
char *p = ptr;
- LIBC_LOCK(stream->lock);
+ LIBC_LOCK(__IMPL(stream)->lock);
while (total > 0) {
- if (stream->buf_pos < stream->buf_len) {
- size_t available = stream->buf_len - stream->buf_pos;
+ if (__IMPL(stream)->buf_pos < __IMPL(stream)->buf_len) {
+ size_t available = __IMPL(stream)->buf_len -
+ __IMPL(stream)->buf_pos;
size_t to_copy = total < available ? total : available;
- memcpy(p, stream->buf + stream->buf_pos, to_copy);
- stream->buf_pos += to_copy;
+ memcpy(p, __IMPL(stream)->buf + __IMPL(stream)->buf_pos,
+ to_copy);
+ __IMPL(stream)->buf_pos += to_copy;
p += to_copy;
bytes_read += to_copy;
total -= to_copy;
continue;
}
- ssize_t ret = read(stream->fd, stream->buf, stream->buf_size);
+ ssize_t ret = read(__IMPL(stream)->fd, __IMPL(stream)->buf,
+ __IMPL(stream)->buf_size);
if (ret <= 0) {
if (ret < 0)
- stream->flags |= _IO_ERR;
+ __IMPL(stream)->flags |= _IO_ERR;
else
- stream->flags |= _IO_EOF;
+ __IMPL(stream)->flags |= _IO_EOF;
break;
}
- stream->buf_len = ret;
- stream->buf_pos = 0;
+ __IMPL(stream)->buf_len = ret;
+ __IMPL(stream)->buf_pos = 0;
}
- LIBC_UNLOCK(stream->lock);
+ LIBC_UNLOCK(__IMPL(stream)->lock);
return bytes_read / size;
}