PatchworkOS
Loading...
Searching...
No Matches
readfile.c
Go to the documentation of this file.
1#include <sys/io.h>
2
3uint64_t readfile(const char* path, void* buffer, uint64_t count, uint64_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
fd_t open(const char *path)
System call for opening files.
Definition open.c:9
uint64_t close(fd_t fd)
System call for closing files.
Definition close.c:9
uint64_t seek(fd_t fd, int64_t offset, seek_origin_t origin)
System call for changing the file offset.
Definition seek.c:9
uint64_t readfile(const char *path, void *buffer, uint64_t count, uint64_t offset)
Wrapper for reading a file directly using a path.
Definition readfile.c:3
uint64_t read(fd_t fd, void *buffer, uint64_t count)
System call for reading from files.
Definition read.c:9
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ fd_t
A file descriptor.
Definition fd_t.h:12
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static atomic_long count
Definition main.c:9
__UINT64_TYPE__ uint64_t
Definition stdint.h:17