diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-02-11 15:40:48 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-02-11 15:40:48 +0100 |
| commit | cd5c9e6a923878e797212d27476ee217eb844a14 (patch) | |
| tree | f5ea8605d0521cbfbf384b05567bf3d2155b0b45 /ft_write.s | |
| parent | 28424105e255f0a4c887b6e6a83afd6dce372709 (diff) | |
| download | libasm-cd5c9e6a923878e797212d27476ee217eb844a14.tar.gz libasm-cd5c9e6a923878e797212d27476ee217eb844a14.tar.bz2 libasm-cd5c9e6a923878e797212d27476ee217eb844a14.zip | |
Added Linux compatibility
Diffstat (limited to 'ft_write.s')
| -rw-r--r-- | ft_write.s | 54 |
1 files changed, 27 insertions, 27 deletions
@@ -10,38 +10,38 @@ ; ; ; **************************************************************************** ; -global _ft_write +%ifdef __LINUX__ + %define M_FT_WRITE ft_write + %define M_ERRNO_LOCATION __errno_location + %define M_SYSCALL_WRITE 0x1 +%else + %define M_FT_WRITE _ft_write + %define M_ERRNO_LOCATION ___error + %define M_SYSCALL_WRITE 0x2000004 +%endif -%define F_GETFD 1 -%define SYSCALL_WRITE 0x2000004 -%define SYSCALL_FCNTL 0x200005c +extern M_ERRNO_LOCATION -; int ft_write(int rdi, const void *rsi, size_t rdx); -_ft_write: - 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 +global M_FT_WRITE - mov rax, SYSCALL_WRITE +section .text +; int ft_write(int rdi, const void *rsi, size_t rdx); +M_FT_WRITE: + mov rax, M_SYSCALL_WRITE syscall +%ifdef __LINUX__ + cmp rax, 0 + jl FT_WRITE_ERROR +%else + jc FT_WRITE_ERROR +%endif ret FT_WRITE_ERROR: +%ifdef __LINUX__ + neg rax +%endif + push rax + call M_ERRNO_LOCATION wrt ..plt + pop qword [rax] mov rax, -1 ret -FT_WRITE_NO_SIZE: - mov rax, 0 - ret |
