From 174a587414513a2f5e2030bf56d54d0b3a58f98f Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 3 Sep 2024 14:34:52 +0200 Subject: [PATCH] add: ft_read --- include/libasm.h | 3 ++- src/ft_read.asm | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/ft_read.asm diff --git a/include/libasm.h b/include/libasm.h index da5d07e..1bef4a0 100644 --- a/include/libasm.h +++ b/include/libasm.h @@ -7,4 +7,5 @@ char *ft_strcpy(char *dest, const char *src); size_t ft_strlen(const char *str); int ft_strcmp( const char *first, const char *second); ssize_t ft_write(int fd, const void *buf, size_t count); -char *ft_strdup(const char *s); \ No newline at end of file +char *ft_strdup(const char *s); +ssize_t ft_read(int fildes, void *buf, size_t nbyte); \ No newline at end of file diff --git a/src/ft_read.asm b/src/ft_read.asm new file mode 100644 index 0000000..f99bc5d --- /dev/null +++ b/src/ft_read.asm @@ -0,0 +1,25 @@ +extern __errno_location + +section .text + global ft_read + ft_read: + + xor rax, rax + + syscall + + cmp rax, 0 + jne syscall_failed + + ret + + syscall_failed: + + neg rax + mov rbx, rax + + call __errno_location wrt ..plt + + mov [rax], rbx + mov rax, -1 + ret \ No newline at end of file