-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.h
More file actions
41 lines (34 loc) · 1.03 KB
/
string.h
File metadata and controls
41 lines (34 loc) · 1.03 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
// string.h clone - SimpleC
#ifndef SIMPLEC_STRING_H
#define SIMPLEC_STRING_H
// strlen: count characters until null terminator
static inline unsigned long strlen(const char *s) {
unsigned long len = 0;
while (*s++) len++;
return len;
}
// strcpy: copy string from src to dest
static inline char *strcpy(char *dest, const char *src) {
char *d = dest;
while ((*d++ = *src++));
return dest;
}
// strcmp: compare two strings
static inline int strcmp(const char *a, const char *b) {
while (*a && (*a == *b)) a++, b++;
return *(unsigned char *)a - *(unsigned char *)b;
}
// memcpy: copy n bytes from src to dest
static inline void *memcpy(void *dest, const void *src, unsigned long n) {
unsigned char *d = dest;
const unsigned char *s = src;
while (n--) *d++ = *s++;
return dest;
}
// memset: fill memory with a byte value
static inline void *memset(void *dest, int val, unsigned long n) {
unsigned char *d = dest;
while (n--) *d++ = (unsigned char)val;
return dest;
}
#endif // SIMPLEC_STRING_H