-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
37 lines (31 loc) · 752 Bytes
/
string.c
File metadata and controls
37 lines (31 loc) · 752 Bytes
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
#include "string.h"
#include <stdint.h>
#include <stdbool.h>
void *memset(void *ptr, char value, size_t num) {
uint8_t *p = (uint8_t *)ptr;
while (num--)
p[num] = (uint8_t)value;
return ptr;
}
void *memcpy(void *destination, const void *source, size_t num) {
uint8_t *dest = (uint8_t *)destination;
const uint8_t *src = (uint8_t *)source;
for (size_t i = 0; i < num; i++)
dest[i] = src[i];
return destination;
}
size_t strlen(const char *str) {
size_t length = 0;
while (str[length])
length++;
return length;
}
const char *strchr(const char *str, char c) {
while (*str != c) {
if (!*str)
return NULL;
else
str++;
}
return str;
}