aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/stdlib/itoa.c
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/itoa.c
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/itoa.c')
-rw-r--r--src/kernel/lib/stdlib/itoa.c70
1 files changed, 36 insertions, 34 deletions
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