This commit is contained in:
Benjamin Kyd
2019-04-25 21:39:31 +01:00
parent 4bc5392ca7
commit da858dfe76
14 changed files with 137 additions and 26 deletions

View File

@@ -27,7 +27,7 @@ void* memmove(void* dst, const void* src, uint32_t size) {
for (uint32_t i = 0; i < size; i++)
d[i] = s[i];
else
for (uint32_t i = size; i--; )
for (uint32_t i = size; --i; )
d[i-1] = s[i-1];
return dst;
}

View File

@@ -1,3 +1,5 @@
#pragma once
#include <lib/stdint.h>
bool memcmp(const void* a, const void* b, uint32_t size);

37
lib/std/stdlib.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "stdlib.h"
#include "string.h"
void swap(int* x, int* y) {
int* t = x;
x = y;
y = t;
}
void reverse(char s[]) {
int i;
int j = strlen(s) - 1;
char c;
for (i = 0; i < j; i++) {
j--;
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
void itoa(int i, char[] s) {
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}

5
lib/std/stdlib.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
void swap(int* a, int* b);
void reverse(char s[])
void itoa(int i, char[] s);

View File

@@ -1,3 +1,5 @@
#pragma once
#include <lib/stdint.h>
uint32_t strlen(char* str);