feat: ft_write
This commit is contained in:
parent
274cf8281e
commit
6285fdd11b
3 changed files with 26 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -1,5 +1,5 @@
|
||||||
NASM=nasm
|
NASM=nasm
|
||||||
NASMFLAGS=-f elf64 -g -F dwarf
|
NASMFLAGS=-f elf64 -g -F dwarf -D PIC
|
||||||
AR=ar
|
AR=ar
|
||||||
ARFLAGS=rcs
|
ARFLAGS=rcs
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
@ -12,7 +12,8 @@ SHARED_LIB=lib$(LIB_NAME).so
|
||||||
|
|
||||||
SRCS=$(SRC_DIR)/ft_strlen.asm \
|
SRCS=$(SRC_DIR)/ft_strlen.asm \
|
||||||
$(SRC_DIR)/ft_strcpy.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))
|
OBJS=$(patsubst $(SRC_DIR)/%.asm,$(OBJ_DIR)/%.o,$(SRCS))
|
||||||
DEPS=$(OBJS:.o=.d)
|
DEPS=$(OBJS:.o=.d)
|
||||||
|
|
|
||||||
21
src/ft_write.asm
Normal file
21
src/ft_write.asm
Normal file
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef MYLIB_H
|
#ifndef MYLIB_H
|
||||||
#define MYLIB_H
|
#define MYLIB_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <sys/types.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
||||||
size_t ft_strlen(char *str);
|
size_t ft_strlen(char *str);
|
||||||
char *ft_strcpy(char *dest, const char *src);
|
char *ft_strcpy(char *dest, const char *src);
|
||||||
int ft_strcmp (const char *p1, const char *p2);
|
int ft_strcmp (const char *p1, const char *p2);
|
||||||
|
ssize_t ft_write(int fildes, const void *buf, size_t nbyte);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue