PatchworkOS
Loading...
Searching...
No Matches
fread.c
Go to the documentation of this file.
1
#include <
stdio.h
>
2
#include <
stdlib.h
>
3
4
#include "
user/common/file.h
"
5
#include "
user/common/syscalls.h
"
6
7
size_t
fread
(
void
*
_RESTRICT
ptr,
size_t
size,
size_t
nmemb,
FILE
*
_RESTRICT
stream)
8
{
9
mtx_lock
(&stream->mtx);
10
11
uint64_t
n = 0;
12
13
if
(
_file_prepare_read
(stream) !=
ERR
)
14
{
15
for
(; n < nmemb; n++)
16
{
17
// TODO: For better performance, read block-wise, not byte-wise.
18
for
(
uint64_t
i = 0; i < size; i++)
19
{
20
if
(
_FILE_CHECK_AVAIL
(stream) ==
ERR
)
21
{
22
mtx_unlock
(&stream->mtx);
23
return
n;
24
}
25
26
((
uint8_t
*)ptr)[n * size + i] =
_FILE_GETC
(stream);
27
}
28
}
29
}
30
31
mtx_unlock
(&stream->mtx);
32
return
n;
33
}
fread
size_t fread(void *_RESTRICT ptr, size_t size, size_t nmemb, FILE *_RESTRICT stream)
Definition
fread.c:7
ERR
#define ERR
Integer error value.
Definition
ERR.h:17
_RESTRICT
#define _RESTRICT
Definition
config.h:17
_file_prepare_read
uint64_t _file_prepare_read(FILE *stream)
Definition
file.c:224
file.h
_FILE_GETC
#define _FILE_GETC(stream)
Definition
file.h:49
_FILE_CHECK_AVAIL
#define _FILE_CHECK_AVAIL(fh)
Definition
file.h:53
syscalls.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:11
stdio.h
stdlib.h
FILE
Definition
file.h:34
mtx_lock
_PUBLIC int mtx_lock(mtx_t *mtx)
Definition
mtx_lock.c:11
mtx_unlock
_PUBLIC int mtx_unlock(mtx_t *mtx)
Definition
mtx_unlock.c:10
src
libstd
user
functions
stdio
fread.c
Generated by
1.9.8