diff --git a/Makefile b/Makefile index 38b83be..c29620a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NASM=nasm -NASMFLAGS=-f elf64 -g -F dwarf +NASMFLAGS=-f elf64 -g -F dwarf -D PIC AR=ar ARFLAGS=rcs CC=gcc @@ -12,7 +12,8 @@ SHARED_LIB=lib$(LIB_NAME).so SRCS=$(SRC_DIR)/ft_strlen.asm \ $(SRC_DIR)/ft_strcpy.asm \ - $(SRC_DIR)/ft_strcmp.asm + $(SRC_DIR)/ft_strcmp.asm \ + $(SRC_DIR)/ft_write.asm OBJS=$(patsubst $(SRC_DIR)/%.asm,$(OBJ_DIR)/%.o,$(SRCS)) DEPS=$(OBJS:.o=.d) diff --git a/src/ft_write.asm b/src/ft_write.asm new file mode 100644 index 0000000..539fdb0 --- /dev/null +++ b/src/ft_write.asm @@ -0,0 +1,21 @@ +global ft_write +extern __errno_location +section .text + +ft_write: + mov eax, 1 + syscall + + ; if rax >= 0 + test rax, rax + jns .done + + neg rax + mov edi, eax + call __errno_location wrt ..plt + mov dword [rax], edi + mov eax, -1 + +.done: + ret + diff --git a/src/mylib.h b/src/mylib.h index b12f01a..9663002 100644 --- a/src/mylib.h +++ b/src/mylib.h @@ -1,7 +1,7 @@ #ifndef MYLIB_H #define MYLIB_H -#include +#include #ifdef __cplusplus extern "C" { #endif @@ -9,6 +9,7 @@ extern "C" { size_t ft_strlen(char *str); char *ft_strcpy(char *dest, const char *src); int ft_strcmp (const char *p1, const char *p2); +ssize_t ft_write(int fildes, const void *buf, size_t nbyte); #ifdef __cplusplus }