PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
readfile.c
Go to the documentation of this file.
1#include <sys/fs.h>
2
3size_t readfile(const char* path, void* buffer, size_t count, size_t offset)
4{
5 fd_t fd = open(path);
6 if (fd == ERR)
7 {
8 return ERR;
9 }
10
11 if (offset != 0 && seek(fd, offset, SEEK_SET) == ERR)
12 {
13 close(fd);
14 return ERR;
15 }
16
17 uint64_t bytesRead = read(fd, buffer, count);
18 close(fd);
19 return bytesRead;
20}
#define SEEK_SET
Definition SEEK.h:4
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
fd_t open(const char *path)
System call for opening files.
Definition open.c:8
uint64_t close(fd_t fd)
System call for closing files.
Definition close.c:8
size_t seek(fd_t fd, ssize_t offset, seek_origin_t origin)
System call for changing the file offset.
Definition seek.c:8
size_t readfile(const char *path, void *buffer, size_t count, size_t offset)
Wrapper for reading a file directly using a path.
Definition readfile.c:3
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
Definition read.c:8
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ fd_t
File descriptor type.
Definition fd_t.h:10
static uint64_t offset
Definition screen.c:19
static atomic_long count
Definition main.c:11
__UINT64_TYPE__ uint64_t
Definition stdint.h:17