aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/stdlib
diff options
context:
space:
mode:
authorMarvin Borner2020-03-18 17:32:50 +0100
committerMarvin Borner2020-03-18 17:32:50 +0100
commitf495cc1e93710c233292a503720ec235a61b685c (patch)
tree23b0b4b82b6d80001c1ffdb15f00b93cbdc65722 /src/kernel/lib/stdlib
parentc6657aac0c5d5ecf347bc082cb6df38e1174d297 (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/kernel/lib/stdlib')
-rw-r--r--src/kernel/lib/stdlib/atoi.c28
-rw-r--r--src/kernel/lib/stdlib/htoa.c33
-rw-r--r--src/kernel/lib/stdlib/htoi.c26
-rw-r--r--src/kernel/lib/stdlib/itoa.c70
4 files changed, 82 insertions, 75 deletions
diff --git a/src/kernel/lib/stdlib/atoi.c b/src/kernel/lib/stdlib/atoi.c
index bcdd395..2d58d84 100644
--- a/src/kernel/lib/stdlib/atoi.c
+++ b/src/kernel/lib/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, (int) ((s_str - i) - 1));
- }
+ int ret = 0;
+ for (; i < s_str; i++) {
+ ret += (str[i] - '0') * pow(10, (int)((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/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c
index 49ca703..ee639ec 100644
--- a/src/kernel/lib/stdlib/htoa.c
+++ b/src/kernel/lib/stdlib/htoa.c
@@ -6,25 +6,26 @@ static const char HTOA_TABLE[] = "0123456789ABCDEF";
char *htoa(uint32_t n)
{
- char *ret = (char *) kmalloc(10);
+ char *ret = (char *)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/kernel/lib/stdlib/htoi.c b/src/kernel/lib/stdlib/htoi.c
index cc77e16..dcc4b63 100644
--- a/src/kernel/lib/stdlib/htoi.c
+++ b/src/kernel/lib/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, (int) ((s_str - i) - 1));
- }
+ ret += aux * pow(16, (int)((s_str - i) - 1));
+ }
- return ret;
+ return ret;
} \ No newline at end of file
diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c
index dec75bf..94c3351 100644
--- a/src/kernel/lib/stdlib/itoa.c
+++ b/src/kernel/lib/stdlib/itoa.c
@@ -8,38 +8,40 @@ static const char ITOA_TABLE[] = "0123456789";
char *itoa(int n)
{
- if (paging_enabled == 0)
- return "0"; // kmalloc isn't available
-
- if (!n) {
- char *ret = (char *) 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 = (char *) kmalloc((uint32_t) (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 = (char *) kmalloc((uint32_t) (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 = (char *)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 = (char *)kmalloc((uint32_t)(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 = (char *)kmalloc((uint32_t)(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