mirror of
https://github.com/cc65/cc65.git
synced 2025-01-12 02:30:44 +00:00
Add standard C library function strnlen().
This commit is contained in:
parent
be594912eb
commit
88fdaeb490
@ -50,6 +50,7 @@ char* __fastcall__ strcpy (char* dest, const char* src);
|
|||||||
size_t __fastcall__ strcspn (const char* s1, const char* s2);
|
size_t __fastcall__ strcspn (const char* s1, const char* s2);
|
||||||
char* __fastcall__ strerror (int errcode);
|
char* __fastcall__ strerror (int errcode);
|
||||||
size_t __fastcall__ strlen (const char* s);
|
size_t __fastcall__ strlen (const char* s);
|
||||||
|
size_t __fastcall__ strnlen (const char* s, size_t maxlen);
|
||||||
char* __fastcall__ strncat (char* s1, const char* s2, size_t count);
|
char* __fastcall__ strncat (char* s1, const char* s2, size_t count);
|
||||||
int __fastcall__ strncmp (const char* s1, const char* s2, size_t count);
|
int __fastcall__ strncmp (const char* s1, const char* s2, size_t count);
|
||||||
char* __fastcall__ strncpy (char* dest, const char* src, size_t count);
|
char* __fastcall__ strncpy (char* dest, const char* src, size_t count);
|
||||||
|
54
libsrc/common/strnlen.s
Normal file
54
libsrc/common/strnlen.s
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
; size_t __fastcall__ strnlen (const char* s, size_t maxlen);
|
||||||
|
|
||||||
|
.export _strnlen
|
||||||
|
.import popax
|
||||||
|
.importzp ptr1, tmp1, tmp2, tmp3, tmp4
|
||||||
|
|
||||||
|
.proc _strnlen
|
||||||
|
; Fetch string pointer.
|
||||||
|
sta ptr1
|
||||||
|
stx ptr1+1
|
||||||
|
|
||||||
|
; Clear return value.
|
||||||
|
lda #0
|
||||||
|
sta tmp1
|
||||||
|
sta tmp2
|
||||||
|
|
||||||
|
; Get maximum length.
|
||||||
|
jsr popax
|
||||||
|
sta tmp3
|
||||||
|
inc tmp3
|
||||||
|
inx
|
||||||
|
stx tmp4
|
||||||
|
|
||||||
|
;;; Loop over string.
|
||||||
|
ldy #0
|
||||||
|
|
||||||
|
; Decrement maximum length.
|
||||||
|
next: dec tmp3
|
||||||
|
bne l2
|
||||||
|
dec tmp4
|
||||||
|
beq done
|
||||||
|
l2:
|
||||||
|
|
||||||
|
lda (ptr1),y
|
||||||
|
beq done
|
||||||
|
|
||||||
|
; Step to next character.
|
||||||
|
inc ptr1
|
||||||
|
bne l1
|
||||||
|
inc ptr1+1
|
||||||
|
l1:
|
||||||
|
|
||||||
|
; Increment return value.
|
||||||
|
inc tmp1
|
||||||
|
bne next
|
||||||
|
inc tmp2
|
||||||
|
|
||||||
|
jmp next
|
||||||
|
|
||||||
|
|
||||||
|
done: lda tmp1
|
||||||
|
ldx tmp2
|
||||||
|
rts
|
||||||
|
.endproc
|
Loading…
x
Reference in New Issue
Block a user