Skip to content

Commit 90953eb

Browse files
committed
Added stpcpy and memccpy calc84maniac
1 parent c0840d5 commit 90953eb

File tree

4 files changed

+106
-27
lines changed

4 files changed

+106
-27
lines changed

src/libc/include/string.h

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,92 @@
55

66
__BEGIN_DECLS
77

8-
extern void *memcpy(void *__restrict dest, const void *__restrict src,
9-
size_t n) __attribute__((nonnull(1, 2)));
8+
extern void *memcpy(void *__restrict dest, const void *__restrict src, size_t n)
9+
__attribute__((nonnull(1, 2)));
1010

1111
void *memmove(void *dest, const void *src, size_t n)
12-
__attribute__((nonnull(1, 2)));
12+
__attribute__((nonnull(1, 2)));
1313

14-
void *memset(void *s, int c, size_t n) __attribute__((nonnull(1)));
14+
void *memset(void *s, int c, size_t n)
15+
__attribute__((nonnull(1)));
1516

1617
int memcmp(const void *s1, const void *s2, size_t n)
17-
__attribute__((nonnull(1, 2)));
18+
__attribute__((nonnull(1, 2)));
1819

19-
void *memchr(const void *s, int c, size_t n) __attribute__((nonnull(1)));
20+
void *memchr(const void *s, int c, size_t n)
21+
__attribute__((nonnull(1)));
22+
23+
void* memccpy(void *__restrict dest, const void *__restrict src, int c, size_t n) __NOEXCEPT
24+
__attribute__((nonnull(1, 2)));
2025

2126
char *strcpy(char *__restrict dest, const char *__restrict src)
22-
__attribute__((nonnull(1, 2)));
27+
__attribute__((nonnull(1, 2)));
2328

2429
char *strncpy(char *__restrict dest, const char *__restrict src, size_t n)
25-
__attribute__((nonnull(1, 2)));
30+
__attribute__((nonnull(1, 2)));
31+
32+
char *stpcpy(char *__restrict dest, const char *__restrict src) __NOEXCEPT
33+
__attribute__((nonnull(1, 2)));
34+
35+
char *stpncpy(char *__restrict dest, const char *__restrict src, size_t n) __NOEXCEPT
36+
__attribute__((nonnull(1, 2)));
37+
38+
char *strlcpy(char *__restrict dest, const char *__restrict src, size_t n) __NOEXCEPT
39+
__attribute__((nonnull(1, 2)));
2640

2741
char *strcat(char *__restrict dest, const char *__restrict src)
28-
__attribute__((nonnull(1, 2)));
42+
__attribute__((nonnull(1, 2)));
2943

3044
char *strncat(char *__restrict dest, const char *__restrict src, size_t n)
31-
__attribute__((nonnull(1, 2)));
45+
__attribute__((nonnull(1, 2)));
46+
47+
char *strlcat(char *__restrict dest, const char *__restrict src, size_t n) __NOEXCEPT
48+
__attribute__((nonnull(1, 2)));
3249

33-
char *strchr(const char *s, int c) __attribute__((nonnull(1)));
50+
char *strchr(const char *s, int c)
51+
__attribute__((nonnull(1)));
3452

35-
char *strrchr(const char *s, int c) __attribute__((nonnull(1)));
53+
char *strrchr(const char *s, int c)
54+
__attribute__((nonnull(1)));
3655

37-
char *strpbrk(const char *s, const char *accept) __attribute__((nonnull(1, 2)));
56+
char *strpbrk(const char *s, const char *accept)
57+
__attribute__((nonnull(1, 2)));
3858

3959
char *strstr(const char *haystack, const char *needle)
40-
__attribute__((nonnull(1, 2)));
60+
__attribute__((nonnull(1, 2)));
4161

4262
char *strtok(char *__restrict s, const char *__restrict delim)
43-
__attribute__((nonnull(2)));
63+
__attribute__((nonnull(2)));
4464

4565
char *strdup(const char *s)
46-
__attribute__ ((__malloc__)) __attribute__((nonnull(1)));
66+
__attribute__((__malloc__)) __attribute__((nonnull(1)));
4767

4868
char *strndup(const char *s, size_t n)
49-
__attribute__ ((__malloc__)) __attribute__((nonnull(1)));
69+
__attribute__((__malloc__)) __attribute__((nonnull(1)));
5070

5171
size_t strcspn(const char *s, const char *reject)
52-
__attribute__((nonnull(1, 2)));
72+
__attribute__((nonnull(1, 2)));
5373

5474
size_t strspn(const char *s, const char *accept)
55-
__attribute__((nonnull(1, 2)));
75+
__attribute__((nonnull(1, 2)));
5676

5777
size_t strlen(const char *s)
58-
__attribute__((nonnull(1)));
78+
__attribute__((nonnull(1)));
5979

6080
size_t strnlen(const char *s, size_t maxlen)
61-
__attribute__((nonnull(1)));
81+
__attribute__((nonnull(1)));
6282

6383
int strcmp(const char *s1, const char *s2)
64-
__attribute__((nonnull(1, 2)));
84+
__attribute__((nonnull(1, 2)));
6585

6686
int strncmp(const char *s1, const char *s2, size_t n)
67-
__attribute__((nonnull(1, 2)));
87+
__attribute__((nonnull(1, 2)));
6888

69-
int strcasecmp(const char *s1, const char *s2)
70-
__attribute__((nonnull(1, 2)));
89+
int strcasecmp(const char *s1, const char *s2) __NOEXCEPT
90+
__attribute__((nonnull(1, 2))) __attribute__((__pure__));
7191

72-
int strncasecmp(const char *s1, const char *s2, size_t n)
73-
__attribute__((nonnull(1, 2)));
92+
int strncasecmp(const char *s1, const char *s2, size_t n) __NOEXCEPT
93+
__attribute__((nonnull(1, 2))) __attribute__((__pure__));
7494

7595
char* strerror(int errnum);
7696

src/libc/memccpy.src

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public _memccpy
6+
7+
_memccpy:
8+
ld iy, 0
9+
add iy, sp
10+
ld bc, (iy + 12)
11+
sbc hl, hl
12+
adc hl, bc
13+
ret z
14+
ld de, (iy + 6)
15+
push de
16+
sbc hl, hl
17+
sbc hl, de
18+
ex de, hl
19+
ld a, (iy + 9)
20+
cpir
21+
add hl, de
22+
ex (sp), hl
23+
pop bc
24+
ld de, (iy + 3)
25+
ldir
26+
ex de, hl
27+
ret z
28+
or a, a
29+
sbc hl, hl
30+
ret

src/libc/stpcpy.src

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public _stpcpy
6+
7+
_stpcpy:
8+
pop bc
9+
pop de
10+
ex (sp), hl
11+
push de
12+
push bc
13+
xor a, a
14+
ld bc, 0
15+
push hl
16+
cpir
17+
sbc hl, hl
18+
sbc hl, bc
19+
ex (sp), hl
20+
pop bc
21+
ldir
22+
ex de, hl
23+
dec hl
24+
ret

src/libcxx/include/cstring

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ using ::memmove;
1414
using ::memset;
1515
using ::memcmp;
1616
using ::memchr;
17+
using ::memccpy;
1718
using ::strcpy;
1819
using ::strncpy;
20+
using ::stpcpy;
21+
using ::stpncpy;
22+
using ::strlcpy;
1923
using ::strcat;
2024
using ::strncat;
25+
using ::strlcat;
2126
using ::strchr;
2227
using ::strrchr;
2328
using ::strpbrk;

0 commit comments

Comments
 (0)