aboutsummaryrefslogtreecommitdiff
path: root/src/userspace/mlibc
diff options
context:
space:
mode:
Diffstat (limited to 'src/userspace/mlibc')
-rw-r--r--src/userspace/mlibc/math/pow.c13
-rw-r--r--src/userspace/mlibc/stdio/getch.c2
-rw-r--r--src/userspace/mlibc/stdio/printf.c8
-rw-r--r--src/userspace/mlibc/stdio/readline.c16
-rw-r--r--src/userspace/mlibc/stdio/vprintf.c73
-rw-r--r--src/userspace/mlibc/stdio/writec.c2
-rw-r--r--src/userspace/mlibc/stdlib/atoi.c28
-rw-r--r--src/userspace/mlibc/stdlib/htoa.c35
-rw-r--r--src/userspace/mlibc/stdlib/htoi.c26
-rw-r--r--src/userspace/mlibc/stdlib/itoa.c76
-rw-r--r--src/userspace/mlibc/stdlib/liballoc.c4
-rw-r--r--src/userspace/mlibc/string/memcmp.c18
-rw-r--r--src/userspace/mlibc/string/memcpy.c9
-rw-r--r--src/userspace/mlibc/string/memset.c7
-rw-r--r--src/userspace/mlibc/string/strcat.c9
-rw-r--r--src/userspace/mlibc/string/strcati.c7
-rw-r--r--src/userspace/mlibc/string/strcmp.c9
-rw-r--r--src/userspace/mlibc/string/strcpy.c7
-rw-r--r--src/userspace/mlibc/string/strdisp.c8
-rw-r--r--src/userspace/mlibc/string/strdup.c10
-rw-r--r--src/userspace/mlibc/string/strinv.c14
-rw-r--r--src/userspace/mlibc/string/strlen.c47
22 files changed, 225 insertions, 203 deletions
diff --git a/src/userspace/mlibc/math/pow.c b/src/userspace/mlibc/math/pow.c
index 24670a0..5cdcfa5 100644
--- a/src/userspace/mlibc/math/pow.c
+++ b/src/userspace/mlibc/math/pow.c
@@ -1,10 +1,13 @@
int pow(int base, int exp)
{
- if (exp < 0) return 0;
+ if (exp < 0)
+ return 0;
- if (!exp) return 1;
+ if (!exp)
+ return 1;
- int ret = base;
- for (int i = 1; i < exp; i++) ret *= base;
- return ret;
+ int ret = base;
+ for (int i = 1; i < exp; i++)
+ ret *= base;
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/getch.c b/src/userspace/mlibc/stdio/getch.c
index dc9c40e..908a871 100644
--- a/src/userspace/mlibc/stdio/getch.c
+++ b/src/userspace/mlibc/stdio/getch.c
@@ -2,5 +2,5 @@
char getch()
{
- return (char) syscall_readc();
+ return (char)syscall_readc();
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/printf.c b/src/userspace/mlibc/stdio/printf.c
index 5617d03..5a50f8d 100644
--- a/src/userspace/mlibc/stdio/printf.c
+++ b/src/userspace/mlibc/stdio/printf.c
@@ -3,8 +3,8 @@
void printf(const char *fmt, ...)
{
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/readline.c b/src/userspace/mlibc/stdio/readline.c
index 68e8499..b59545b 100644
--- a/src/userspace/mlibc/stdio/readline.c
+++ b/src/userspace/mlibc/stdio/readline.c
@@ -3,12 +3,12 @@
char *readline()
{
- char *ret = malloc(256);
- char buf = 0;
- while (buf != '\n') {
- buf = getch();
- writec(buf);
- strcpy(ret, &buf);
- }
- return ret;
+ char *ret = malloc(256);
+ char buf = 0;
+ while (buf != '\n') {
+ buf = getch();
+ writec(buf);
+ strcpy(ret, &buf);
+ }
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/vprintf.c b/src/userspace/mlibc/stdio/vprintf.c
index 2536b79..0f5ae68 100644
--- a/src/userspace/mlibc/stdio/vprintf.c
+++ b/src/userspace/mlibc/stdio/vprintf.c
@@ -5,47 +5,48 @@
void _writes(const char *data)
{
- for (size_t i = 0; i < strlen(data); i++) writec(data[i]);
+ for (size_t i = 0; i < strlen(data); i++)
+ writec(data[i]);
}
void vprintf(const char *fmt, va_list args)
{
- uint8_t readyToFormat = 0;
+ uint8_t readyToFormat = 0;
- char buff = 0;
+ char buff = 0;
- for (; *fmt; fmt++) {
- if (readyToFormat) {
- if (*fmt == '%') {
- writec('%');
- readyToFormat = 0;
- continue;
- }
+ for (; *fmt; fmt++) {
+ if (readyToFormat) {
+ if (*fmt == '%') {
+ writec('%');
+ readyToFormat = 0;
+ continue;
+ }
- buff = *fmt;
- if (buff == 's') {
- const char *str = va_arg(args, const char*);
- _writes(str);
- readyToFormat = 0;
- } else if (buff == 'x') {
- char *p = htoa((uint32_t) va_arg(args, int));
- _writes(p);
- free(p);
- readyToFormat = 0;
- } else if (buff == 'd') {
- char *p = itoa(va_arg(args, int));
- _writes(p);
- free(p);
- readyToFormat = 0;
- } else if (buff == 'c') {
- writec((char) va_arg(args, int));
- readyToFormat = 0;
- }
- } else {
- if (*fmt == '%')
- readyToFormat = 1;
- else
- writec(*fmt);
- }
- }
+ buff = *fmt;
+ if (buff == 's') {
+ const char *str = va_arg(args, const char *);
+ _writes(str);
+ readyToFormat = 0;
+ } else if (buff == 'x') {
+ char *p = htoa((uint32_t)va_arg(args, int));
+ _writes(p);
+ free(p);
+ readyToFormat = 0;
+ } else if (buff == 'd') {
+ char *p = itoa(va_arg(args, int));
+ _writes(p);
+ free(p);
+ readyToFormat = 0;
+ } else if (buff == 'c') {
+ writec((char)va_arg(args, int));
+ readyToFormat = 0;
+ }
+ } else {
+ if (*fmt == '%')
+ readyToFormat = 1;
+ else
+ writec(*fmt);
+ }
+ }
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/writec.c b/src/userspace/mlibc/stdio/writec.c
index ee588e5..1f918b6 100644
--- a/src/userspace/mlibc/stdio/writec.c
+++ b/src/userspace/mlibc/stdio/writec.c
@@ -2,5 +2,5 @@
void writec(char c)
{
- syscall_writec(c);
+ syscall_writec(c);
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdlib/atoi.c b/src/userspace/mlibc/stdlib/atoi.c
index 67a603e..f1c3755 100644
--- a/src/userspace/mlibc/stdlib/atoi.c
+++ b/src/userspace/mlibc/stdlib/atoi.c
@@ -5,20 +5,24 @@
int atoi(char *str)
{
- size_t s_str = strlen(str);
- if (!s_str) return 0;
+ size_t s_str = strlen(str);
+ if (!s_str)
+ return 0;
- uint8_t negative = 0;
- if (str[0] == '-') negative = 1;
+ uint8_t negative = 0;
+ if (str[0] == '-')
+ negative = 1;
- size_t i = 0;
- if (negative) i++;
+ size_t i = 0;
+ if (negative)
+ i++;
- int ret = 0;
- for (; i < s_str; i++) {
- ret += (str[i] - '0') * pow(10, (s_str - i) - 1);
- }
+ int ret = 0;
+ for (; i < s_str; i++) {
+ ret += (str[i] - '0') * pow(10, (s_str - i) - 1);
+ }
- if (negative) ret *= -1;
- return ret;
+ if (negative)
+ ret *= -1;
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdlib/htoa.c b/src/userspace/mlibc/stdlib/htoa.c
index 579db5d..42cc71c 100644
--- a/src/userspace/mlibc/stdlib/htoa.c
+++ b/src/userspace/mlibc/stdlib/htoa.c
@@ -6,26 +6,27 @@ static const char HTOA_TABLE[] = "0123456789ABCDEF";
char *htoa(uint32_t n)
{
- char *ret = 0;
- //kmalloc(10);
+ char *ret = 0;
+ //kmalloc(10);
- int i = 0;
- while (n) {
- ret[i++] = HTOA_TABLE[n & 0xF];
- n >>= 4;
- }
+ int i = 0;
+ while (n) {
+ ret[i++] = HTOA_TABLE[n & 0xF];
+ n >>= 4;
+ }
- if (!i) {
- ret[0] = '0';
- i++;
- }
+ if (!i) {
+ ret[0] = '0';
+ i++;
+ }
- for (; i <= 9; i++) ret[i] = 0;
+ for (; i <= 9; i++)
+ ret[i] = 0;
- char *aux = strdup(ret);
- // kfree(ret);
- ret = aux;
+ char *aux = strdup(ret);
+ // kfree(ret);
+ ret = aux;
- strinv(ret);
- return ret;
+ strinv(ret);
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdlib/htoi.c b/src/userspace/mlibc/stdlib/htoi.c
index 93b387a..69149d6 100644
--- a/src/userspace/mlibc/stdlib/htoi.c
+++ b/src/userspace/mlibc/stdlib/htoi.c
@@ -4,20 +4,20 @@
int htoi(char *str)
{
- size_t s_str = strlen(str);
+ size_t s_str = strlen(str);
- size_t i = 0;
- int ret = 0;
- for (; i < s_str; i++) {
- char c = str[i];
- int aux = 0;
- if (c >= '0' && c <= '9')
- aux = c - '0';
- else if (c >= 'A' && c <= 'F')
- aux = (c - 'A') + 10;
+ size_t i = 0;
+ int ret = 0;
+ for (; i < s_str; i++) {
+ char c = str[i];
+ int aux = 0;
+ if (c >= '0' && c <= '9')
+ aux = c - '0';
+ else if (c >= 'A' && c <= 'F')
+ aux = (c - 'A') + 10;
- ret += aux * pow(16, (s_str - i) - 1);
- }
+ ret += aux * pow(16, (s_str - i) - 1);
+ }
- return ret;
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdlib/itoa.c b/src/userspace/mlibc/stdlib/itoa.c
index 567824f..6db7539 100644
--- a/src/userspace/mlibc/stdlib/itoa.c
+++ b/src/userspace/mlibc/stdlib/itoa.c
@@ -6,41 +6,43 @@ static const char ITOA_TABLE[] = "0123456789";
char *itoa(int n)
{
- //if (paging_enabled == 0)
- // return "0"; // kmalloc isn't available
-
- if (!n) {
- char *ret = 0;
- //kmalloc(2);
- ret[0] = '0';
- ret[1] = 0;
- return ret;
- }
- uint8_t negative = (uint8_t) (n < 0);
- if (negative) n *= -1;
-
- int sz;
- for (sz = 0; n % pow(10, sz) != n; sz++) {}
-
- char *ret = 0;
- //kmalloc(sz + 1);
-
- for (int i = 0; i < sz; i++) {
- int digit = (n % pow(10, i + 1)) / pow(10, i);
- ret[i] = ITOA_TABLE[digit];
- }
- ret[sz] = 0;
-
- if (negative) {
- char *aux = 0;
- //kmalloc(sz + 2);
- strcpy(aux, ret);
- aux[sz] = '-';
- aux[sz + 1] = 0;
- // kfree(ret);
- ret = aux;
- }
-
- strinv(ret);
- return ret;
+ //if (paging_enabled == 0)
+ // return "0"; // kmalloc isn't available
+
+ if (!n) {
+ char *ret = 0;
+ //kmalloc(2);
+ ret[0] = '0';
+ ret[1] = 0;
+ return ret;
+ }
+ uint8_t negative = (uint8_t)(n < 0);
+ if (negative)
+ n *= -1;
+
+ int sz;
+ for (sz = 0; n % pow(10, sz) != n; sz++) {
+ }
+
+ char *ret = 0;
+ //kmalloc(sz + 1);
+
+ for (int i = 0; i < sz; i++) {
+ int digit = (n % pow(10, i + 1)) / pow(10, i);
+ ret[i] = ITOA_TABLE[digit];
+ }
+ ret[sz] = 0;
+
+ if (negative) {
+ char *aux = 0;
+ //kmalloc(sz + 2);
+ strcpy(aux, ret);
+ aux[sz] = '-';
+ aux[sz + 1] = 0;
+ // kfree(ret);
+ ret = aux;
+ }
+
+ strinv(ret);
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdlib/liballoc.c b/src/userspace/mlibc/stdlib/liballoc.c
index 2a10c0d..0b62f9a 100644
--- a/src/userspace/mlibc/stdlib/liballoc.c
+++ b/src/userspace/mlibc/stdlib/liballoc.c
@@ -3,10 +3,10 @@
void *malloc(size_t count)
{
- return (void *) syscall_alloc(count);
+ return (void *)syscall_alloc(count);
}
void free(void *ptr)
{
- syscall_free((uint32_t) ptr);
+ syscall_free((uint32_t)ptr);
}
diff --git a/src/userspace/mlibc/string/memcmp.c b/src/userspace/mlibc/string/memcmp.c
index af2125c..f1f1e3f 100644
--- a/src/userspace/mlibc/string/memcmp.c
+++ b/src/userspace/mlibc/string/memcmp.c
@@ -2,13 +2,13 @@
int memcmp(const void *a_ptr, const void *b_ptr, size_t size)
{
- const unsigned char *a = (const unsigned char *) a_ptr;
- const unsigned char *b = (const unsigned char *) b_ptr;
- for (size_t i = 0; i < size; i++) {
- if (a[i] < b[i])
- return -1;
- else if (b[i] < a[i])
- return 1;
- }
- return 0;
+ const unsigned char *a = (const unsigned char *)a_ptr;
+ const unsigned char *b = (const unsigned char *)b_ptr;
+ for (size_t i = 0; i < size; i++) {
+ if (a[i] < b[i])
+ return -1;
+ else if (b[i] < a[i])
+ return 1;
+ }
+ return 0;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/memcpy.c b/src/userspace/mlibc/string/memcpy.c
index e4e9c76..eec798b 100644
--- a/src/userspace/mlibc/string/memcpy.c
+++ b/src/userspace/mlibc/string/memcpy.c
@@ -2,8 +2,9 @@
void *memcpy(void *dest, const void *src, size_t count)
{
- const char *sp = (const char *) src;
- char *dp = (char *) dest;
- for (; count != 0; count--) *dp++ = *sp++;
- return dest;
+ const char *sp = (const char *)src;
+ char *dp = (char *)dest;
+ for (; count != 0; count--)
+ *dp++ = *sp++;
+ return dest;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/memset.c b/src/userspace/mlibc/string/memset.c
index fb5ab80..1d9bec1 100644
--- a/src/userspace/mlibc/string/memset.c
+++ b/src/userspace/mlibc/string/memset.c
@@ -2,7 +2,8 @@
void *memset(void *dest, char val, size_t count)
{
- char *temp = (char *) dest;
- for (; count != 0; count--) *temp++ = val;
- return dest;
+ char *temp = (char *)dest;
+ for (; count != 0; count--)
+ *temp++ = val;
+ return dest;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strcat.c b/src/userspace/mlibc/string/strcat.c
index 2876604..0374e6c 100644
--- a/src/userspace/mlibc/string/strcat.c
+++ b/src/userspace/mlibc/string/strcat.c
@@ -2,9 +2,10 @@
void strcat(char *dest, const char *orig)
{
- size_t s_dest = strlen(dest);
- size_t s_orig = strlen(orig);
+ size_t s_dest = strlen(dest);
+ size_t s_orig = strlen(orig);
- for (size_t i = 0; i < s_orig; i++) dest[s_dest + i] = orig[i];
- dest[s_dest + s_orig] = 0;
+ for (size_t i = 0; i < s_orig; i++)
+ dest[s_dest + i] = orig[i];
+ dest[s_dest + s_orig] = 0;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strcati.c b/src/userspace/mlibc/string/strcati.c
index 312792f..be39b51 100644
--- a/src/userspace/mlibc/string/strcati.c
+++ b/src/userspace/mlibc/string/strcati.c
@@ -2,7 +2,8 @@
void strcati(char *dest, const char *orig)
{
- size_t s_orig = strlen(orig);
- strdisp(dest, (int) s_orig);
- for (size_t i = 0; i < s_orig; i++) dest[i] = orig[i];
+ size_t s_orig = strlen(orig);
+ strdisp(dest, (int)s_orig);
+ for (size_t i = 0; i < s_orig; i++)
+ dest[i] = orig[i];
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strcmp.c b/src/userspace/mlibc/string/strcmp.c
index 903234f..8cbf189 100644
--- a/src/userspace/mlibc/string/strcmp.c
+++ b/src/userspace/mlibc/string/strcmp.c
@@ -2,9 +2,12 @@
char strcmp(const char *a, const char *b)
{
- if (strlen(a) != strlen(b)) return 1;
+ if (strlen(a) != strlen(b))
+ return 1;
- for (size_t i = 0; i < strlen(a); i++) if (a[i] != b[i]) return 1;
+ for (size_t i = 0; i < strlen(a); i++)
+ if (a[i] != b[i])
+ return 1;
- return 0;
+ return 0;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strcpy.c b/src/userspace/mlibc/string/strcpy.c
index 18f3f25..3a4832c 100644
--- a/src/userspace/mlibc/string/strcpy.c
+++ b/src/userspace/mlibc/string/strcpy.c
@@ -2,8 +2,9 @@
void strcpy(char *dest, const char *orig)
{
- size_t s_orig = strlen(orig);
+ size_t s_orig = strlen(orig);
- for (size_t i = 0; i < s_orig; i++) dest[i] = orig[i];
- dest[s_orig] = 0;
+ for (size_t i = 0; i < s_orig; i++)
+ dest[i] = orig[i];
+ dest[s_orig] = 0;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strdisp.c b/src/userspace/mlibc/string/strdisp.c
index 5d8ee7d..51c5a90 100644
--- a/src/userspace/mlibc/string/strdisp.c
+++ b/src/userspace/mlibc/string/strdisp.c
@@ -2,11 +2,13 @@
void strdisponce(char *str)
{
- for (size_t i = sizeof(str) + 2; i > 0; i--) str[i] = str[i - 1];
- str[0] = 0;
+ for (size_t i = sizeof(str) + 2; i > 0; i--)
+ str[i] = str[i - 1];
+ str[0] = 0;
}
void strdisp(char *str, int n)
{
- for (int i = 0; i < n; i++) strdisponce(str);
+ for (int i = 0; i < n; i++)
+ strdisponce(str);
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strdup.c b/src/userspace/mlibc/string/strdup.c
index e77536c..6a4fa86 100644
--- a/src/userspace/mlibc/string/strdup.c
+++ b/src/userspace/mlibc/string/strdup.c
@@ -3,9 +3,9 @@
char *strdup(const char *orig)
{
- // size_t s_orig = strlen(orig);
- char *ret = 0;
- // kmalloc(s_orig + 1);
- strcpy(ret, orig);
- return ret;
+ // size_t s_orig = strlen(orig);
+ char *ret = 0;
+ // kmalloc(s_orig + 1);
+ strcpy(ret, orig);
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strinv.c b/src/userspace/mlibc/string/strinv.c
index 4f54775..20b916e 100644
--- a/src/userspace/mlibc/string/strinv.c
+++ b/src/userspace/mlibc/string/strinv.c
@@ -2,12 +2,12 @@
void strinv(char *str)
{
- size_t s_str = strlen(str);
+ size_t s_str = strlen(str);
- int iterations = (int) s_str / 2;
- for (int i = 0; i < iterations; i++) {
- char aux = str[i];
- str[i] = str[(s_str - i) - 1];
- str[(s_str - i) - 1] = aux;
- }
+ int iterations = (int)s_str / 2;
+ for (int i = 0; i < iterations; i++) {
+ char aux = str[i];
+ str[i] = str[(s_str - i) - 1];
+ str[(s_str - i) - 1] = aux;
+ }
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/strlen.c b/src/userspace/mlibc/string/strlen.c
index c8d9c4f..f652495 100644
--- a/src/userspace/mlibc/string/strlen.c
+++ b/src/userspace/mlibc/string/strlen.c
@@ -2,33 +2,34 @@
size_t strlen(const char *str)
{
- const char *char_ptr;
- const unsigned long int *longword_ptr;
- unsigned long int longword, himagic, lomagic;
+ const char *char_ptr;
+ const unsigned long int *longword_ptr;
+ unsigned long int longword, himagic, lomagic;
- for (char_ptr = str; ((unsigned long int) char_ptr & (sizeof(longword) - 1)) != 0; ++char_ptr)
- if (*char_ptr == '\0')
- return char_ptr - str;
+ for (char_ptr = str; ((unsigned long int)char_ptr & (sizeof(longword) - 1)) != 0;
+ ++char_ptr)
+ if (*char_ptr == '\0')
+ return char_ptr - str;
- longword_ptr = (unsigned long int *) char_ptr;
+ longword_ptr = (unsigned long int *)char_ptr;
- himagic = 0x80808080L;
- lomagic = 0x01010101L;
+ himagic = 0x80808080L;
+ lomagic = 0x01010101L;
- for (;;) {
- longword = *longword_ptr++;
+ for (;;) {
+ longword = *longword_ptr++;
- if (((longword - lomagic) & himagic) != 0) {
- const char *cp = (const char *) (longword_ptr - 1);
+ if (((longword - lomagic) & himagic) != 0) {
+ const char *cp = (const char *)(longword_ptr - 1);
- if (cp[0] == 0)
- return cp - str;
- if (cp[1] == 0)
- return cp - str + 1;
- if (cp[2] == 0)
- return cp - str + 2;
- if (cp[3] == 0)
- return cp - str + 3;
- }
- }
+ if (cp[0] == 0)
+ return cp - str;
+ if (cp[1] == 0)
+ return cp - str + 1;
+ if (cp[2] == 0)
+ return cp - str + 2;
+ if (cp[3] == 0)
+ return cp - str + 3;
+ }
+ }
} \ No newline at end of file