Adds strlcpy()

This commit is contained in:
2025-06-24 15:53:24 +02:00
parent d3e7f47259
commit e620754b13
2 changed files with 70 additions and 1 deletions

View File

@ -15,6 +15,7 @@ extern puts
;string.asm
extern strlen
extern strcpy
extern strlcpy
extern strcat
extern strcmp
@ -29,6 +30,7 @@ section .rodata
TEST_islower equ 1
TEST_isupper equ 1
TEST_strcpy equ 1
TEST_strlcpy equ 1
TEST_strcat equ 1
TEST_tolower equ 1
TEST_toupper equ 1
@ -57,6 +59,9 @@ section .rodata
msgIsupper db "isupper(str1[0]): %d",10,0
msgIsupper2 db "isupper(str1[1]): %d",10,0
msgStrcpy db "strcpy(strBuff, str1): %s",10,0
msgStrlcpy db "strlcpy(strBuff2, str1, -1): (%d): %s",10,0
msgStrlcpy2 db "strlcpy(strBuff2, str1, 0): (%d): %s",10,0
msgStrlcpy3 db "strlcpy(strBuff2, str1, 8): (%d): %s",10,0
msgStrcat db "strcat(strBuff, str3): %s",10,0
msgStrlen3 db "strlen(strBuff): %d",10,0
msgTolower db "tolower(str1[0]): %c",10,0
@ -70,7 +75,8 @@ section .rodata
msgStrcmp2 db "strcmp(str1, strBuff): %d",10,0
section .data
section .bss
strBuff resb 32
strBuff resb 32
strBuff2 resb 5
section .text
global main
main:
@ -215,6 +221,38 @@ main:
lea rsi, [rel strBuff]
call printf
%ENDIF
%IF TEST_strlcpy
; TEST: strlcpy(strBuff2, str1, -1)
lea rdi, [rel strBuff2]
lea rsi, [rel str1]
mov rdx, -1
call strlcpy
mov rsi, rax
xor rax, rax
lea rdi, [rel msgStrlcpy]
lea rdx, [rel strBuff2]
call printf
; TEST: strlcpy(strBuff2, str1, 0)
lea rdi, [rel strBuff2]
lea rsi, [rel str1]
mov rdx, 0
call strlcpy
mov rsi, rax
xor rax, rax
lea rdi, [rel msgStrlcpy2]
lea rdx, [rel strBuff2]
call printf
; TEST: strlcpy(strBuff2, str1, 8)
lea rdi, [rel strBuff2]
lea rsi, [rel str1]
mov rdx, 5
call strlcpy
mov rsi, rax
xor rax, rax
lea rdi, [rel msgStrlcpy3]
lea rdx, [rel strBuff2]
call printf
%ENDIF
%IF TEST_strcat
; TEST: strcat()
lea rdi, [rel strBuff]