summaryrefslogtreecommitdiff
path: root/userland/libc/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/stdlib')
-rw-r--r--userland/libc/stdlib/abort.c2
-rw-r--r--userland/libc/stdlib/abs.c4
-rw-r--r--userland/libc/stdlib/atexit.c4
-rw-r--r--userland/libc/stdlib/atof.c2
-rw-r--r--userland/libc/stdlib/atoi.c4
-rw-r--r--userland/libc/stdlib/getenv.c6
-rw-r--r--userland/libc/stdlib/mkstemp.c7
-rw-r--r--userland/libc/stdlib/qsort.c5
-rw-r--r--userland/libc/stdlib/strtod.c6
-rw-r--r--userland/libc/stdlib/strtol.c9
-rw-r--r--userland/libc/stdlib/strtoll.c11
-rw-r--r--userland/libc/stdlib/strtoul.c9
-rw-r--r--userland/libc/stdlib/system.c5
13 files changed, 47 insertions, 27 deletions
diff --git a/userland/libc/stdlib/abort.c b/userland/libc/stdlib/abort.c
index 90368a9..5279676 100644
--- a/userland/libc/stdlib/abort.c
+++ b/userland/libc/stdlib/abort.c
@@ -1,6 +1,6 @@
#include <assert.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/abort.html
void abort(void) {
diff --git a/userland/libc/stdlib/abs.c b/userland/libc/stdlib/abs.c
index 1079beb..9e50b0a 100644
--- a/userland/libc/stdlib/abs.c
+++ b/userland/libc/stdlib/abs.c
@@ -1,3 +1,5 @@
#include <stdlib.h>
-int abs(int i) { return (i < 0) ? (-i) : (i); }
+int abs(int i) {
+ return (i < 0) ? (-i) : (i);
+}
diff --git a/userland/libc/stdlib/atexit.c b/userland/libc/stdlib/atexit.c
index 0e401ff..1dc34cc 100644
--- a/userland/libc/stdlib/atexit.c
+++ b/userland/libc/stdlib/atexit.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
int atexit(void (*func)(void)) {
- //TODO
- return 0;
+ // TODO
+ return 0;
}
diff --git a/userland/libc/stdlib/atof.c b/userland/libc/stdlib/atof.c
index 8524f8b..f008852 100644
--- a/userland/libc/stdlib/atof.c
+++ b/userland/libc/stdlib/atof.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
double atof(const char *str) {
- return strtod(str,(char **)NULL);
+ return strtod(str, (char **)NULL);
}
diff --git a/userland/libc/stdlib/atoi.c b/userland/libc/stdlib/atoi.c
index 2183306..876f69a 100644
--- a/userland/libc/stdlib/atoi.c
+++ b/userland/libc/stdlib/atoi.c
@@ -1,4 +1,6 @@
#include <stdlib.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/
-int atoi(const char *str) { return (int)strtol(str, (char **)NULL, 10); }
+int atoi(const char *str) {
+ return (int)strtol(str, (char **)NULL, 10);
+}
diff --git a/userland/libc/stdlib/getenv.c b/userland/libc/stdlib/getenv.c
index 13d871c..0240d66 100644
--- a/userland/libc/stdlib/getenv.c
+++ b/userland/libc/stdlib/getenv.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
char *getenv(const char *name) {
- (void)name;
- // FIXME
- return NULL;
+ (void)name;
+ // FIXME
+ return NULL;
}
diff --git a/userland/libc/stdlib/mkstemp.c b/userland/libc/stdlib/mkstemp.c
index 1ea8790..0dec8e9 100644
--- a/userland/libc/stdlib/mkstemp.c
+++ b/userland/libc/stdlib/mkstemp.c
@@ -1,14 +1,17 @@
#include <fcntl.h>
#include <stdlib.h>
-char rand_char(void) { return 'A' + (rand() % 10); }
+char rand_char(void) {
+ return 'A' + (rand() % 10);
+}
int mkstemp(char *template) {
// FIXME: Incomplete
const char *s = template;
for (; *template; template ++) {
- if ('X' == *template)
+ if ('X' == *template) {
*template = rand_char();
+ }
}
return open(s, O_RDWR, O_CREAT);
}
diff --git a/userland/libc/stdlib/qsort.c b/userland/libc/stdlib/qsort.c
index 3f87db5..f60fa5d 100644
--- a/userland/libc/stdlib/qsort.c
+++ b/userland/libc/stdlib/qsort.c
@@ -6,9 +6,10 @@ void qsort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *)) {
// If the nel argument has the value zero, the comparison function pointed to
// by compar shall not be called and no rearrangement shall take place.
- if (0 == nel)
+ if (0 == nel) {
return;
-
+ }
+
// AB
// Results in negative
// BA
diff --git a/userland/libc/stdlib/strtod.c b/userland/libc/stdlib/strtod.c
index 2c83879..01119bb 100644
--- a/userland/libc/stdlib/strtod.c
+++ b/userland/libc/stdlib/strtod.c
@@ -1,8 +1,10 @@
+#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
-#include <assert.h>
-int ctoi(char c) { return c - '0'; }
+int ctoi(char c) {
+ return c - '0';
+}
double strtod(const char *restrict nptr, char **restrict endptr) {
double r = 0;
diff --git a/userland/libc/stdlib/strtol.c b/userland/libc/stdlib/strtol.c
index 460dedd..0b1bbad 100644
--- a/userland/libc/stdlib/strtol.c
+++ b/userland/libc/stdlib/strtol.c
@@ -9,13 +9,15 @@ int get_value(char c, long base);
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtol.html
long strtol(const char *str, char **restrict endptr, int base) {
long ret_value = 0;
- if (endptr)
+ if (endptr) {
*endptr = (char *)str;
+ }
// Ignore inital white-space sequence
for (; *str && isspace(*str); str++)
;
- if (!*str)
+ if (!*str) {
return ret_value;
+ }
// int sign = 0;
if ('-' == *str) {
@@ -63,7 +65,8 @@ long strtol(const char *str, char **restrict endptr, int base) {
errno = EINVAL;
return 0;
}
- if (endptr)
+ if (endptr) {
*endptr = (char *)str;
+ }
return ret_value;
}
diff --git a/userland/libc/stdlib/strtoll.c b/userland/libc/stdlib/strtoll.c
index 0e397ff..9a2a624 100644
--- a/userland/libc/stdlib/strtoll.c
+++ b/userland/libc/stdlib/strtoll.c
@@ -9,13 +9,15 @@ int get_value(char c, long base);
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoll.html
long long strtoll(const char *str, char **restrict endptr, int base) {
long long ret_value = 0;
- if (endptr)
+ if (endptr) {
*endptr = (char *)str;
+ }
// Ignore inital white-space sequence
for (; *str && isspace(*str); str++)
;
- if (!*str)
+ if (!*str) {
return ret_value;
+ }
// int sign = 0;
if ('-' == *str) {
@@ -45,7 +47,7 @@ long long strtoll(const char *str, char **restrict endptr, int base) {
if (2 <= base && 36 >= base) {
for (; *str; str++) {
int val = get_value(*str, base);
- if(-1 == val) {
+ if (-1 == val) {
break;
}
if (ret_value > LLONG_MAX / base) {
@@ -63,7 +65,8 @@ long long strtoll(const char *str, char **restrict endptr, int base) {
errno = EINVAL;
return 0;
}
- if (endptr)
+ if (endptr) {
*endptr = (char *)str;
+ }
return ret_value;
}
diff --git a/userland/libc/stdlib/strtoul.c b/userland/libc/stdlib/strtoul.c
index 39dc8eb..0f2c71b 100644
--- a/userland/libc/stdlib/strtoul.c
+++ b/userland/libc/stdlib/strtoul.c
@@ -25,13 +25,15 @@ int get_value(char c, long base) {
unsigned long strtoul(const char *restrict str, char **restrict endptr,
int base) {
unsigned long ret_value = 0;
- if (endptr)
+ if (endptr) {
*endptr = (char *)str;
+ }
// Ignore inital white-space sequence
for (; *str && isspace(*str); str++)
;
- if (!*str)
+ if (!*str) {
return ret_value;
+ }
// int sign = 0;
if ('-' == *str) {
@@ -79,7 +81,8 @@ unsigned long strtoul(const char *restrict str, char **restrict endptr,
errno = EINVAL;
return 0;
}
- if (endptr)
+ if (endptr) {
*endptr = (char *)str;
+ }
return ret_value;
}
diff --git a/userland/libc/stdlib/system.c b/userland/libc/stdlib/system.c
index 1cba966..c35bee5 100644
--- a/userland/libc/stdlib/system.c
+++ b/userland/libc/stdlib/system.c
@@ -1,10 +1,11 @@
#include <stdlib.h>
-#include <unistd.h>
#include <sys/wait.h>
+#include <unistd.h>
int system(const char *command) {
- if (!command)
+ if (!command) {
return NULL;
+ }
int pid = fork();
if (0 == pid) {
char *argv[2];