Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libc/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ char *strcasestr(const char *haystack, const char *needle)
char *strtok(char *__restrict s, const char *__restrict delim)
__attribute__((nonnull(2)));

char *strsep(char **__restrict s, const char *__restrict delim)
__NOEXCEPT __attribute__((nonnull(1, 2)));

char *strdup(const char *s)
__attribute__((__malloc__)) __attribute__((nonnull(1)));

Expand Down
46 changes: 46 additions & 0 deletions src/libc/strsep.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
assume adl=1

section .text

public _strsep

; char *strsep(char **__restrict stringp, const char *__restrict delim)
_strsep:
pop bc
pop hl
pop de
push de
push hl
push bc
push hl ; stringp
ld hl, (hl)
add hl, de
or a, a
sbc hl, de
jr z, .ret_null
push de ; delim
push hl ; *stringp
call _strcspn
pop de
pop de
pop iy ; stringp
ld de, (iy)
add hl, de ; *stringp + length
xor a, a
cp a, (hl) ; test for the nul terminator
jr nz, .not_last_token
sbc hl, hl ; last token
jr .finish
.not_last_token:
ld (hl), a ; nul terminate
inc hl ; next token
.finish:
ld (iy), hl ; store the next token
ex de, hl
; return *stringp
ret
.ret_null:
pop de
ret

extern _strcspn
1 change: 1 addition & 0 deletions src/libcxx/include/cstring
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ using ::strstr;
using ::strrstr;
using ::strcasestr;
using ::strtok;
using ::strsep;
using ::strdup;
using ::strndup;
using ::strcspn;
Expand Down
Loading
Loading