I write program on c and I need to use functions from assembly. I think when a syscall is facing a problem it returns a negative value and write it to rax, but it doesn't do it.
I use macOS and NASM. To be more precise, my write function is:
global _ft_write
extern ___error
_ft_write:
mov rax, 0x2000004
syscall
ret
for compile: nasm -fmacho64
and main:
#include <stdio.h>
#include <errno.h>
int ft_write(int fd, const void *buf, size_t nbytes);
int main(void)
{
printf("%d", ft_write(-15, "wrong file descriptor", 3));
return (1);
}
expexted output: -9
my output: 9
I tried to use read only files, but output was 9 too. Were is mistake? Why rax is non negative after syscall error and how can I receive syscall return after error?