diff options
author | Marvin Borner | 2020-03-18 17:32:50 +0100 |
---|---|---|
committer | Marvin Borner | 2020-03-18 17:32:50 +0100 |
commit | f495cc1e93710c233292a503720ec235a61b685c (patch) | |
tree | 23b0b4b82b6d80001c1ffdb15f00b93cbdc65722 /src/userspace/mlibc/stdlib | |
parent | c6657aac0c5d5ecf347bc082cb6df38e1174d297 (diff) |
Applied official linux kernel code style guidelines
Due to my change to vim and the clang-format plugin this was needed!
Diffstat (limited to 'src/userspace/mlibc/stdlib')
-rw-r--r-- | src/userspace/mlibc/stdlib/atoi.c | 28 | ||||
-rw-r--r-- | src/userspace/mlibc/stdlib/htoa.c | 35 | ||||
-rw-r--r-- | src/userspace/mlibc/stdlib/htoi.c | 26 | ||||
-rw-r--r-- | src/userspace/mlibc/stdlib/itoa.c | 76 | ||||
-rw-r--r-- | src/userspace/mlibc/stdlib/liballoc.c | 4 |
5 files changed, 88 insertions, 81 deletions
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); } |