feat: Vfs and Ext2 support. Code style/attribute improvements

Added VFS and Ext2 support.
Optimized attributes of methods to improve code highlighting.
Printf attribute, malloc attribute, etc.
This commit is contained in:
2021-10-06 21:45:15 +02:00
parent 073051c99e
commit 03f0ec6f88
24 changed files with 1322 additions and 90 deletions

View File

@@ -68,6 +68,11 @@ uint32_t vasprintf(char *buf, const char *fmt, va_list args) {
++i;
}
}
int l = 0;
while (fmt[i] == 'l') {
l++;
i++;
}
switch (fmt[i]) {
case 's': { // string
uint32_t j = 0;
@@ -87,7 +92,12 @@ uint32_t vasprintf(char *buf, const char *fmt, va_list args) {
case 'x':
case 'p':
case 'X': // todo capitalize
print_int((uint32_t) va_arg(args, uint32_t), field_width, buf, &ptr, 16);
if (l == 0 || l == 1) {
print_int((uint32_t) va_arg(args, uint32_t), field_width, buf, &ptr, 16);
} else if (l == 2) {
print_int((uint64_t) va_arg(args, uint64_t), field_width, buf, &ptr, 16);
}
// todo error
break;
case 'i':
case 'd':

View File

@@ -22,7 +22,7 @@ void *memset(void *dst, int data, size_t amount) {
}
void *memmove(void *dst, const void *src, size_t amount) {
void* tmp = malloc(amount);
void *tmp = malloc(amount);
if (tmp == NULL) {
return NULL;
}
@@ -48,16 +48,19 @@ size_t strlen(const char *str) {
}
int strcmp(const char *s1, const char *s2) {
int len1 = strlen(s1);
int len2 = strlen(s2);
size_t len1 = strlen(s1);
size_t len2 = strlen(s2);
return strncmp(s1, s2, MAX(len1, len2));
}
const char *strchr(const char *s, char c) {
int index = 0;
char *strchr(const char *s, char c) {
size_t index = 0;
while (1) {
if (s[index] == c) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
return &s[index];
#pragma clang diagnostic pop
}
if (s[index] == 0) {
return NULL;
@@ -66,11 +69,14 @@ const char *strchr(const char *s, char c) {
}
}
const char *strrchr(const char *s, char c) {
int index = strlen(s);
char *strrchr(const char *s, char c) {
size_t index = strlen(s);
while (1) {
if (s[index] == c) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
return &s[index];
#pragma clang diagnostic pop
}
if (index == 0) {
return NULL;
@@ -90,8 +96,8 @@ int memcmp(const void *s1, const void *s2, size_t n) {
return 0;
}
int strncmp(const char *s1, const char *s2, int n) {
for (int i = 0; i < n; ++i) {
int strncmp(const char *s1, const char *s2, size_t n) {
for (size_t i = 0; i < n; ++i) {
if (s1[i] == 0 && s2[i] == 0) {
return 0;
}