Go to the source code of this file.
|
| void * | memcpy (void *dest, const void *src, size_t n) |
| |
| void * | memmove (void *dest, const void *src, size_t n) |
| |
| void * | memset (void *dest, int val, size_t n) |
| |
| int | memcmp (const void *str1, const void *str2, size_t n) |
| |
| const void * | memchr (const void *str, int c, size_t n) |
| |
| char * | strcpy (char *dest, const char *src) |
| |
| char * | strncpy (char *dest, const char *src, size_t n) |
| |
| char * | strcat (char *dest, const char *src) |
| |
| int | strcmp (const char *s1, const char *s2) |
| |
| int | strncmp (const char *s1, const char *s2, size_t n) |
| |
| size_t | strlen (const char *s) |
| |
| size_t | strnlen (const char *s, size_t n) |
| |
| const char * | strchr (const char *s, int c) |
| |
| const char * | strrchr (const char *s, int c) |
| |
◆ memchr()
| const void * memchr |
( |
const void * |
str, |
|
|
int |
c, |
|
|
size_t |
n |
|
) |
| |
Definition at line 62 of file sk_string.c.
62 {
63 const unsigned char* src = (const unsigned char*)str;
64 unsigned char uc = (unsigned char)c;
65
66 while (n-- > 0) {
67 if (*src == uc) {
68 return (void*)src;
69 }
70 src++;
71 }
72 return NULL;
73}
◆ memcmp()
| int memcmp |
( |
const void * |
str1, |
|
|
const void * |
str2, |
|
|
size_t |
n |
|
) |
| |
Definition at line 49 of file sk_string.c.
49 {
50 const unsigned char* s1 = (const unsigned char*)str1;
51 const unsigned char* s2 = (const unsigned char*)str2;
52
53 while (n-- > 0) {
54 if (*s1++ != *s2++) {
55 return s1[-1] < s2[-1] ? -1 : 1;
56 }
57 }
58 return 0;
59}
◆ memcpy()
| void * memcpy |
( |
void * |
dest, |
|
|
const void * |
src, |
|
|
size_t |
n |
|
) |
| |
- Copyright
- Copyright The SimpleKernel Contributors
Definition at line 12 of file sk_string.c.
12 {
13 char* d = (char*)dest;
14 const char* s = (const char*)src;
15 while (n--) {
16 *d++ = *s++;
17 }
18 return dest;
19}
◆ memmove()
| void * memmove |
( |
void * |
dest, |
|
|
const void * |
src, |
|
|
size_t |
n |
|
) |
| |
Definition at line 22 of file sk_string.c.
22 {
23 char* d = (char*)dest;
24 const char* s = (const char*)src;
25 if (d < s) {
26 while (n--) {
27 *d++ = *s++;
28 }
29 } else {
30 const char* lasts = s + (n - 1);
31 char* lastd = d + (n - 1);
32 while (n--) {
33 *lastd-- = *lasts--;
34 }
35 }
36 return dest;
37}
◆ memset()
| void * memset |
( |
void * |
dest, |
|
|
int |
val, |
|
|
size_t |
n |
|
) |
| |
Definition at line 40 of file sk_string.c.
40 {
41 unsigned char* ptr = (unsigned char*)dest;
42 while (n-- > 0) {
43 *ptr++ = val;
44 }
45 return dest;
46}
◆ strcat()
| char * strcat |
( |
char * |
dest, |
|
|
const char * |
src |
|
) |
| |
Definition at line 94 of file sk_string.c.
94 {
95 char* add_d = dest;
96 if (dest != 0 && src != 0) {
97 while (*add_d) {
98 add_d++;
99 }
100 while (*src) {
101 *add_d++ = *src++;
102 }
103 *add_d = '\0';
104 }
105 return dest;
106}
◆ strchr()
| const char * strchr |
( |
const char * |
s, |
|
|
int |
c |
|
) |
| |
Definition at line 152 of file sk_string.c.
152 {
153 char ch = (char)c;
154 do {
155 if (*s == ch) {
156 return (char*)s;
157 }
158 } while (*s++);
159 return NULL;
160}
◆ strcmp()
| int strcmp |
( |
const char * |
s1, |
|
|
const char * |
s2 |
|
) |
| |
Definition at line 109 of file sk_string.c.
109 {
110 while (*s1 && (*s1 == *s2)) {
111 s1++;
112 s2++;
113 }
114 return *(const unsigned char*)s1 - *(const unsigned char*)s2;
115}
◆ strcpy()
| char * strcpy |
( |
char * |
dest, |
|
|
const char * |
src |
|
) |
| |
Definition at line 76 of file sk_string.c.
76 {
77 char* address = dest;
78 while ((*dest++ = *src++) != '\0') {
79 ;
80 }
81 return address;
82}
◆ strlen()
| size_t strlen |
( |
const char * |
s | ) |
|
Definition at line 134 of file sk_string.c.
134 {
135 size_t len = 0;
136 while (s[len]) {
137 len++;
138 }
139 return len;
140}
◆ strncmp()
| int strncmp |
( |
const char * |
s1, |
|
|
const char * |
s2, |
|
|
size_t |
n |
|
) |
| |
Definition at line 118 of file sk_string.c.
118 {
119 if (n == 0) {
120 return 0;
121 }
122 do {
123 if (*s1 != *s2++) {
124 return (*(const unsigned char*)s1 - *(const unsigned char*)(s2 - 1));
125 }
126 if (*s1++ == '\0') {
127 break;
128 }
129 } while (--n != 0);
130 return 0;
131}
◆ strncpy()
| char * strncpy |
( |
char * |
dest, |
|
|
const char * |
src, |
|
|
size_t |
n |
|
) |
| |
Definition at line 85 of file sk_string.c.
85 {
87 if (size != n) {
88 memset(dest + size,
'\0', n - size);
89 }
90 return (
char*)
memcpy(dest, src, size);
91}
◆ strnlen()
| size_t strnlen |
( |
const char * |
s, |
|
|
size_t |
n |
|
) |
| |
Definition at line 143 of file sk_string.c.
143 {
144 const char* p = s;
145 while (n-- > 0 && *p) {
146 p++;
147 }
148 return p - s;
149}
◆ strrchr()
| const char * strrchr |
( |
const char * |
s, |
|
|
int |
c |
|
) |
| |
Definition at line 163 of file sk_string.c.
163 {
164 char* rtnval = 0;
165 char ch = (char)c;
166
167 do {
168 if (*s == ch) {
169 rtnval = (char*)s;
170 }
171 } while (*s++);
172 return (rtnval);
173}