From b1d9e74023c0310d7a5463f6fd6ef436430c00e6 Mon Sep 17 00:00:00 2001 From: Namonay Date: Tue, 19 Mar 2024 06:54:34 +0100 Subject: [PATCH] :( --- ft_strdup.s | 5 ++--- ft_write.s | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ft_strdup.s b/ft_strdup.s index 9f48a77..465b7d5 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -12,11 +12,10 @@ ft_strdup: call malloc wrt ..plt test rax, rax je .end - pop r8 + pop rsi mov rdi, rax ; move the result of malloc into rdi (override strlen result) - mov rsi, r8 ; move the argument of strdup in rsi call ft_strcpy - ret + ret .end: pop r8 diff --git a/ft_write.s b/ft_write.s index 02992bb..950f211 100644 --- a/ft_write.s +++ b/ft_write.s @@ -2,12 +2,28 @@ global ft_write extern __errno_location ft_write: + cmp rdi, 0 + jl .err_fd + test rsi, rsi + je .err_buffer mov eax, 0x1 ; put the syscall number of write syscall test rax, rax js .error ret +.err_fd: + call __errno_location wrt ..plt + mov byte [rax], 22 + mov rax, -1 + ret + +.err_buffer: + call __errno_location wrt ..plt + mov byte [rax], 22 + mov rax, -1 + ret + .error: mov rdx, rax call __errno_location wrt ..plt