Skip to content

Commit 981c934

Browse files
committed
Lecture 110 - Compiling and testing FREAD
1 parent 6d60640 commit 981c934

13 files changed

Lines changed: 15 additions & 5 deletions

File tree

PeachOS64Bit/programs/blank/blank.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ int main(int argc, char** argv)
88
int fd = fopen("@:/blank.elf", "r");
99
if (fd > 0)
1010
{
11+
12+
char buf[512] = {0};
1113
printf("File blank.elf opened\n");
14+
fread(buf, 1, sizeof(buf), fd);
15+
1216
fclose(fd);
1317
}
1418
else
336 Bytes
Binary file not shown.
472 Bytes
Binary file not shown.
216 Bytes
Binary file not shown.
448 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

PeachOS64Bit/programs/stdlib/src/file.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef USERLAND_FILE_H
22
#define USERLAND_FILE_H
33

4+
#include <stdint.h>
5+
#include <stddef.h>
6+
47
int fopen(const char* filename, const char* mode);
58
void fclose(int fd);
69
int fread(void* buffer, size_t size, size_t count, long fd);

PeachOS64Bit/programs/stdlib/src/peachos.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ global peachos_system:function
1313
global peachos_exit:function
1414
global peachos_fopen:function
1515
global peachos_fclose:function
16-
global peachos_read:function
16+
global peachos_fread:function
1717

1818
; void print(const char* filename)
1919
print:
@@ -101,8 +101,8 @@ peachos_fclose:
101101
add rsp, 8 ; restore the stack
102102
ret
103103

104-
; long peachos_read(void* buffer, size_t size, size_t count, long fd);
105-
peachos_read:
104+
; long peachos_fread(void* buffer, size_t size, size_t count, long fd);
105+
peachos_fread:
106106
mov rax, 12 ; Command 12 fread
107107
push qword rcx ; fd
108108
push qword rdx ; count

PeachOS64Bit/programs/stdlib/src/peachos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ void peachos_exit();
3434

3535
int peachos_fopen(const char* filename, const char* mode);
3636
void peachos_fclose(size_t fd);
37-
long peachos_read(void* buffer, size_t size, size_t count, long fd);
37+
long peachos_fread(void* buffer, size_t size, size_t count, long fd);
3838

3939
#endif
464 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)