This commit is contained in:
janis 2025-10-20 00:51:48 +02:00
parent 208e05b1e6
commit 669650ffea
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8

View file

@ -187,6 +187,46 @@ memcpy:
.done:
ret
;; Returns a pointer to the first occurrence of c in s, or null if not found
;; rdi: pointer to byte slice
;; rsi: length of byte slice
;; dl: byte to find
;; fn strchr(s: &[u8], c: u8) -> &[u8]
strchr:
; if s.len() == 0 {
test rsi, rsi
; return &[];
je .null
; } else {
xor r8, r8
; for i in 0..s.len() {
.loop:
cmp r8, rsi
jge .null
; if s[i] == c {
mov al, [rdi + r8]
cmp al, dl
; return &s[i..];
je .found
; }
inc r8
; }
jmp .loop
; }
.null:
xor rax, rax
xor rdx, rdx
ret
.found:
add rdi, r8
mov rax, rdi
mov rdx, rsi
sub rdx, r8
ret
section .rdata
e_is_dir db "Is a directory", 10
e_is_dir_len equ $ - e_is_dir