blob: a18735f4a5e19a1d8228c66e89bccd20f22b5188 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "stddef.h"
int strcmp(const char* s, const char* t) {
while (*s == *t) {
if (*s == '\0') {
return 0;
}
s++;
t++;
}
return *s - *t;
}
void* memset(char* s, int c, size_t n) {
size_t i;
for (i = 0; i < n; i++) {
s[i] = c;
}
return s;
}
int strncmp(const char* s, const char* t, int n) {
int i;
for (i = 0; (*s == *t) && (i < n); i++) {
if (*s == '\0') {
if (*t == '\0') {
return 0;
}
break;
}
if (*t == '\0') {
break;
}
s++;
t++;
}
return (i != n) ? *s - *t : 0;
}
|