aboutsummaryrefslogtreecommitdiff
path: root/ft_write.s
diff options
context:
space:
mode:
Diffstat (limited to 'ft_write.s')
-rw-r--r--ft_write.s32
1 files changed, 30 insertions, 2 deletions
diff --git a/ft_write.s b/ft_write.s
index 2e3ba00..0761329 100644
--- a/ft_write.s
+++ b/ft_write.s
@@ -12,8 +12,36 @@
global ft_write
-; int ft_write(int, const void*, size_t);
+%define F_GETFD 1
+%define SYSCALL_WRITE 0x2000004
+%define SYSCALL_FCNTL 0x200005c
+
+; int ft_write(int rdi, const void *rsi, size_t rdx);
ft_write:
- mov rax, 0x2000004
+ cmp rdx, 0
+ je FT_WRITE_NO_SIZE
+ cmp rdi, 0
+ jl FT_WRITE_ERROR ; fd < 0
+ cmp rsi, 0
+ je FT_WRITE_ERROR ; buf == NULL
+
+ push rdx
+ push rsi
+ xor rsi, rsi
+ mov esi, F_GETFD
+ mov rax, SYSCALL_FCNTL
+ syscall
+ pop rsi
+ pop rdx
+ cmp eax, 0
+ jne FT_WRITE_ERROR
+
+ mov rax, SYSCALL_WRITE
syscall
ret
+FT_WRITE_ERROR:
+ mov rax, -1
+ ret
+FT_WRITE_NO_SIZE:
+ mov rax, 0
+ ret