「✨」 feat(ft_read): added read yayy
This commit is contained in:
22
src/sys/ft_read.s
Normal file
22
src/sys/ft_read.s
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
extern __errno_location
|
||||||
|
|
||||||
|
section .text
|
||||||
|
global ft_read
|
||||||
|
|
||||||
|
; ssize_t ft_read(int fd, void *buf, size_t count);
|
||||||
|
ft_read:
|
||||||
|
mov eax, 0
|
||||||
|
syscall
|
||||||
|
|
||||||
|
cmp rax, 0
|
||||||
|
jle .error
|
||||||
|
|
||||||
|
.ret:
|
||||||
|
ret
|
||||||
|
|
||||||
|
.error:
|
||||||
|
mov r10, rax
|
||||||
|
call __errno_location wrt ..plt
|
||||||
|
mov [rax], r10
|
||||||
|
mov rax, -1
|
||||||
|
jmp .ret
|
||||||
@@ -3,7 +3,7 @@ extern __errno_location
|
|||||||
section .text
|
section .text
|
||||||
global ft_write
|
global ft_write
|
||||||
|
|
||||||
; ssize_t write(int fd, const void *buf, size_t count);
|
; ssize_t ft_write(int fd, const void *buf, size_t count);
|
||||||
ft_write:
|
ft_write:
|
||||||
mov eax, 1
|
mov eax, 1
|
||||||
syscall
|
syscall
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ int ft_strlen(char *str);
|
|||||||
char *ft_strcpy(char *dest, const char *src);
|
char *ft_strcpy(char *dest, const char *src);
|
||||||
int ft_strcmp(const char *s1, const char *s2);
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
int ft_write(int fd, const char *buf, unsigned int count);
|
int ft_write(int fd, const char *buf, unsigned int count);
|
||||||
|
int ft_read(int fd, char *buf, unsigned int count);
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -38,4 +40,14 @@ int main(void)
|
|||||||
printf("| 200 \"xd\" 2 | %d\n", ft_write(200, "xd", 2));
|
printf("| 200 \"xd\" 2 | %d\n", ft_write(200, "xd", 2));
|
||||||
int fd = open("out", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
int fd = open("out", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
printf("| %d \"[...]\" 42 | %d\n", fd, ft_write(fd, "wizard money gang, we love casting spells\n", 42));
|
printf("| %d \"[...]\" 42 | %d\n", fd, ft_write(fd, "wizard money gang, we love casting spells\n", 42));
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
printf("\n--- ft_read ---\n");
|
||||||
|
char *xd = calloc(sizeof(char), 43);
|
||||||
|
printf("| 200 _ 2 | %d : %s\n", ft_read(200, xd, 6), xd);
|
||||||
|
fd = open("out", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
|
printf("| %d _ 42 | %d : %s\n", fd, ft_read(fd, xd, 42), xd);
|
||||||
|
|
||||||
|
printf("\n--- ft_strdup ---\n");
|
||||||
|
printf("HELL NAH\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user