-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
87 lines (77 loc) · 1.64 KB
/
Copy pathstring.cpp
File metadata and controls
87 lines (77 loc) · 1.64 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module;
#include <cstdint>
#include <cstddef>
#include <algorithm>
module string;
extern "C" {
void *memcpy(void *dest, const void *src, size_t n) {
uint8_t *d = (uint8_t *)dest;
uint8_t *s = (uint8_t *)src;
while(n--) *d++ = *s++;
return dest;
}
bool memzero(const void *s, size_t n) {
const char *c = (const char *)s;
for (size_t i = 0; i < n; ++i) {
if (c[i] != 0) return false;
}
return true;
}
void *memchr(const void *s, int c, size_t n) {
const unsigned char *p = (const unsigned char *)s;
while (n--) {
if (*p == (unsigned char)c) return (void *)p;
p++;
}
return nullptr;
}
void *memset(void *s, int c, size_t n) {
uint8_t *d = (uint8_t *)s;
while(n--) *d++ = c;
return s;
}
int strcmp(const char *s1, const char *s2) {
while (*s1 && (*s1 == *s2)) {
s1++;
s2++;
}
return *(const unsigned char *)s1 - *(const unsigned char *)s2;
}
int memcmp(const void *s1, const void *s2, size_t n) {
const unsigned char *t1 = (const unsigned char *)s1;
const unsigned char *t2 = (const unsigned char *)s2;
while ((*t1 == *t2)) {
t1++;
t2++;
n--;
}
if (n == 0) return 0;
return *t1 - *t2;
}
int strncmp(const char *s1, const char *s2, size_t n) {
while (n && *s1 && (*s1 == *s2)) {
s1++;
s2++;
n--;
}
if (n == 0) return 0;
return *(const unsigned char *)s1 - *(const unsigned char *)s2;
}
char *strncpy(char *dest, const char *src, size_t n) {
char *d = dest;
while (n > 0 && *src != '\0') {
*d++ = *src++;
n--;
}
while (n > 0) {
*d++ = '\0';
n--;
}
return dest;
}
size_t strlen(const char *s) {
size_t len = 0;
while (*s++) len++;
return len;
}
}