blob: dc5c0ace54a077dc16708fcac2b5861d506bc675 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include <stddef.h>
#include <stdint.h>
// TODO clean up variable names
int strncmp(const char *s1, const char *s2, unsigned int n) {
int i;
for(i = 0; ((i <= n) && (s1[i] != '\0') && (s2[i] != '\0')); i++) {
if(s1[i] != s2[i]) {
return(s1[i] - s2[i]);
}
}
return(s1[i] - s2[i]);
}
int strcmp(const char *s1, const char *s2) {
int i;
for(i = 0; ((s1[i] != '\0') && (s2[i] != '\0')); i++) {
if(s1[i] != s2[i]) {
return(s1[i] - s2[i]);
}
}
return(s1[i] - s2[i]);
}
int memcmp(const void *s1, const void *s2, size_t n) {
const unsigned char *p1 = s1;
const unsigned char *p2 = s2;
int i;
for(i = 0; i < n; i++) {
if(p1[i] != p2[i]) {
return(p1[i] - p2[i]);
}
}
return(p1[n-1] - p2[n-1]);
}
void strcpy(char *dest, char *src) {
for(unsigned int i = 0; src[i] != '\0'; i++){
dest[i] = src[i];
}
}
void memcpy(char *dest, char *src, size_t n) {
for(unsigned int i = 0; i <= n; i++) {
dest[i] = src[i];
}
}
void bzero(void *dest, size_t size) {
unsigned char *p1 = dest;
for(uint64_t i = 0; i < size; i++) {
p1[i] = 0;
}
}
//TODO move this function to a seperate math library
int ceil(float n) {
int low_n = (int)n;
if(n == (float)low_n) return(low_n);
return(low_n + 1);
}
|