-
Notifications
You must be signed in to change notification settings - Fork 1
/
clib.h
66 lines (54 loc) · 1.21 KB
/
clib.h
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
// UEFI From Scratch for AARCH64 - ThatOSDev ( 2024 )
// https://github.com/ThatOSDev/EFI_AARCH64
#ifndef C_LIB_H
#define C_LIB_H
#include <stddef.h> // size_t
size_t strlen(const char* str)
{
const char* strCount = str;
while (*strCount++);
return strCount - str - 1;
}
int strcmp(const char* a, const char* b)
{
size_t length = strlen(a);
for(size_t i = 0; i < length; i++)
{
if(a[i] < b[i]){return -1;}
if(a[i] > b[i]){return 1;}
}
return 0;
}
void itoa(uint64_t n, uint64_t* buffer, uint32_t basenumber)
{
unsigned long int hold;
int i, j;
hold = n;
i = 0;
do{
hold = n % basenumber;
buffer[i++] = (hold < 10) ? (hold + '0') : (hold + 'a' - 10);
} while(n /= basenumber);
buffer[i--] = 0;
for(j = 0; j < i; j++, i--)
{
hold = buffer[j];
buffer[j] = buffer[i];
buffer[i] = hold;
}
}
void* memcpy(void* destination, const void* source, size_t num)
{
for (size_t i = 0; i < num; i++)
((uint8_t*) destination)[i] = ((uint8_t*) source)[i];
return destination;
}
// GCC Version
void *memset (void *dest, register int val, register size_t len)
{
register unsigned char *ptr = (unsigned char*)dest;
while (len-- > 0)
*ptr++ = val;
return dest;
}
#endif // C_LIB_H