summaryrefslogtreecommitdiff
path: root/userland/libc
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc')
-rw-r--r--userland/libc/Makefile1
-rw-r--r--userland/libc/arpa/inet/ntohl.c4
-rw-r--r--userland/libc/arpa/inet/ntohs.c2
-rw-r--r--userland/libc/ctype/isalnum.c2
-rw-r--r--userland/libc/ctype/isalpha.c4
-rw-r--r--userland/libc/ctype/isascii.c4
-rw-r--r--userland/libc/ctype/isblank.c2
-rw-r--r--userland/libc/ctype/iscntrl.c5
-rw-r--r--userland/libc/ctype/isprint.c4
-rw-r--r--userland/libc/ctype/ispunct.c2
-rw-r--r--userland/libc/ctype/tolower.c3
-rw-r--r--userland/libc/ctype/toupper.c3
-rw-r--r--userland/libc/dirent/readdir.c6
-rw-r--r--userland/libc/dirent/scandir.c6
-rw-r--r--userland/libc/fcntl/open.c2
-rw-r--r--userland/libc/include/assert.h4
-rw-r--r--userland/libc/include/math.h12
-rw-r--r--userland/libc/include/pty.h4
-rw-r--r--userland/libc/include/setjmp.h6
-rw-r--r--userland/libc/include/sys/sendfile.h7
-rw-r--r--userland/libc/include/tb/sb.h3
-rw-r--r--userland/libc/isspace.c2
-rw-r--r--userland/libc/libgen/basename.c12
-rw-r--r--userland/libc/libgen/dirname.c18
-rw-r--r--userland/libc/malloc/malloc.h2
-rw-r--r--userland/libc/memset.c3
-rw-r--r--userland/libc/pty.c20
-rw-r--r--userland/libc/signal/sigaction.c5
-rw-r--r--userland/libc/stdio/feof.c2
-rw-r--r--userland/libc/stdio/ferror.c2
-rw-r--r--userland/libc/stdio/fflush.c2
-rw-r--r--userland/libc/stdio/fgetc.c9
-rw-r--r--userland/libc/stdio/fgets.c9
-rw-r--r--userland/libc/stdio/fileno.c2
-rw-r--r--userland/libc/stdio/fputc.c3
-rw-r--r--userland/libc/stdio/fputs.c6
-rw-r--r--userland/libc/stdio/fscanf.c2
-rw-r--r--userland/libc/stdio/getchar.c4
-rw-r--r--userland/libc/stdio/open_memstream.c9
-rw-r--r--userland/libc/stdio/putc.c4
-rw-r--r--userland/libc/stdio/remove.c4
-rw-r--r--userland/libc/stdio/rename.c2
-rw-r--r--userland/libc/stdio/stdin.c6
-rw-r--r--userland/libc/stdio/tmpfile.c10
-rw-r--r--userland/libc/stdio/ungetc.c3
-rw-r--r--userland/libc/stdio/vfprintf.c42
-rw-r--r--userland/libc/stdio/vprintf.c4
-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
-rw-r--r--userland/libc/string/memchr.c2
-rw-r--r--userland/libc/string/memcmp.c6
-rw-r--r--userland/libc/string/memcpy.c12
-rw-r--r--userland/libc/string/sscanf.c12
-rw-r--r--userland/libc/string/strcasecmp.c6
-rw-r--r--userland/libc/string/strchr.c8
-rw-r--r--userland/libc/string/strcmp.c6
-rw-r--r--userland/libc/string/strcspn.c2
-rw-r--r--userland/libc/string/strdup.c3
-rw-r--r--userland/libc/string/strlcpy.c6
-rw-r--r--userland/libc/string/strncasecmp.c8
-rw-r--r--userland/libc/string/strncmp.c6
-rw-r--r--userland/libc/string/strncpy.c6
-rw-r--r--userland/libc/string/strndup.c5
-rw-r--r--userland/libc/string/strnlen.c6
-rw-r--r--userland/libc/string/strpbrk.c2
-rw-r--r--userland/libc/string/strrchr.c8
-rw-r--r--userland/libc/string/strspn.c3
-rw-r--r--userland/libc/string/strstr.c10
-rw-r--r--userland/libc/string/strtok.c12
-rw-r--r--userland/libc/sys/mman.h2
-rw-r--r--userland/libc/sys/mman/mmap.c4
-rw-r--r--userland/libc/sys/mman/munmap.c2
-rw-r--r--userland/libc/sys/sendfile.c2
-rw-r--r--userland/libc/sys/socket/listen.c6
-rw-r--r--userland/libc/sys/socket/sendto.c2
-rw-r--r--userland/libc/sys/time/gettimeofday.c6
-rw-r--r--userland/libc/sys/types.h4
-rw-r--r--userland/libc/tb/sha1.c37
-rw-r--r--userland/libc/time/gmtime.c2
-rw-r--r--userland/libc/time/localtime.c28
-rw-r--r--userland/libc/time/strftime.c8
-rw-r--r--userland/libc/time/time.c3
-rw-r--r--userland/libc/ubsan.c4
-rw-r--r--userland/libc/unistd/_exit.c4
-rw-r--r--userland/libc/unistd/chdir.c6
-rw-r--r--userland/libc/unistd/getpid.c6
-rw-r--r--userland/libc/unistd/isatty.c5
-rw-r--r--userland/libc/unistd/msleep.c6
-rw-r--r--userland/libc/unistd/unlink.c2
-rw-r--r--userland/libc/unistd/uptime.c4
-rw-r--r--userland/libc/unistd/write.c2
102 files changed, 378 insertions, 243 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile
index e5aeff1..19dabe6 100644
--- a/userland/libc/Makefile
+++ b/userland/libc/Makefile
@@ -6,6 +6,7 @@ OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset
all: libc.a
%.o: %.c
+ clang-format -i $<
$(CC) $(CFLAGS) -I. -o $@ -c $<
%.o: %.s
diff --git a/userland/libc/arpa/inet/ntohl.c b/userland/libc/arpa/inet/ntohl.c
index 456819d..4cf3d8c 100644
--- a/userland/libc/arpa/inet/ntohl.c
+++ b/userland/libc/arpa/inet/ntohl.c
@@ -2,4 +2,6 @@
#include <endian.h>
#include <stdint.h>
-uint32_t ntohl(uint32_t nl) { return htonl(nl); }
+uint32_t ntohl(uint32_t nl) {
+ return htonl(nl);
+}
diff --git a/userland/libc/arpa/inet/ntohs.c b/userland/libc/arpa/inet/ntohs.c
index e0324ff..0a97b50 100644
--- a/userland/libc/arpa/inet/ntohs.c
+++ b/userland/libc/arpa/inet/ntohs.c
@@ -3,5 +3,5 @@
#include <stdint.h>
uint16_t ntohs(uint16_t nl) {
- return htons(nl);
+ return htons(nl);
}
diff --git a/userland/libc/ctype/isalnum.c b/userland/libc/ctype/isalnum.c
index 870728d..073b8bb 100644
--- a/userland/libc/ctype/isalnum.c
+++ b/userland/libc/ctype/isalnum.c
@@ -2,5 +2,5 @@
// This is probably the most useless libc function I have seen so far.
int isalnum(int c) {
- return isalpha(c) || isdigit(c);
+ return isalpha(c) || isdigit(c);
}
diff --git a/userland/libc/ctype/isalpha.c b/userland/libc/ctype/isalpha.c
index 130f493..38c3cb4 100644
--- a/userland/libc/ctype/isalpha.c
+++ b/userland/libc/ctype/isalpha.c
@@ -1,4 +1,6 @@
#include <ctype.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/isalpha.html
-int isalpha(int c) { return (('A' <= toupper(c)) && ('Z' >= toupper(c))); }
+int isalpha(int c) {
+ return (('A' <= toupper(c)) && ('Z' >= toupper(c)));
+}
diff --git a/userland/libc/ctype/isascii.c b/userland/libc/ctype/isascii.c
index 660c8bb..b598dde 100644
--- a/userland/libc/ctype/isascii.c
+++ b/userland/libc/ctype/isascii.c
@@ -1,4 +1,6 @@
#include <ctype.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/isascii.html
-int isascii(int c) { return (c < 128); }
+int isascii(int c) {
+ return (c < 128);
+}
diff --git a/userland/libc/ctype/isblank.c b/userland/libc/ctype/isblank.c
index 488fa88..88ffa0b 100644
--- a/userland/libc/ctype/isblank.c
+++ b/userland/libc/ctype/isblank.c
@@ -1,5 +1,5 @@
#include <ctype.h>
int isblank(int c) {
- return (c == ' ' || c == '\t');
+ return (c == ' ' || c == '\t');
}
diff --git a/userland/libc/ctype/iscntrl.c b/userland/libc/ctype/iscntrl.c
index 92ed7f0..4fead0d 100644
--- a/userland/libc/ctype/iscntrl.c
+++ b/userland/libc/ctype/iscntrl.c
@@ -1,6 +1,5 @@
#include <ctype.h>
-int iscntrl(int c)
-{
- return (unsigned)c < 0x20 || c == 0x7f;
+int iscntrl(int c) {
+ return (unsigned)c < 0x20 || c == 0x7f;
}
diff --git a/userland/libc/ctype/isprint.c b/userland/libc/ctype/isprint.c
index e6a3d0e..5504ebc 100644
--- a/userland/libc/ctype/isprint.c
+++ b/userland/libc/ctype/isprint.c
@@ -1,3 +1,5 @@
#include <ctype.h>
-int isprint(int c) { return c > 0x20 && 0x7F != c; }
+int isprint(int c) {
+ return c > 0x20 && 0x7F != c;
+}
diff --git a/userland/libc/ctype/ispunct.c b/userland/libc/ctype/ispunct.c
index 18dc7d8..abef66d 100644
--- a/userland/libc/ctype/ispunct.c
+++ b/userland/libc/ctype/ispunct.c
@@ -2,5 +2,5 @@
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/ispunct.html
int ispunct(int c) {
- return (c == '.');
+ return (c == '.');
}
diff --git a/userland/libc/ctype/tolower.c b/userland/libc/ctype/tolower.c
index f1bb163..c14ea54 100644
--- a/userland/libc/ctype/tolower.c
+++ b/userland/libc/ctype/tolower.c
@@ -1,7 +1,8 @@
#include <ctype.h>
int tolower(int c) {
- if (c >= 'A' && c <= 'Z')
+ if (c >= 'A' && c <= 'Z') {
return c - 'A' + 'a';
+ }
return c;
}
diff --git a/userland/libc/ctype/toupper.c b/userland/libc/ctype/toupper.c
index 0f33886..599a0ff 100644
--- a/userland/libc/ctype/toupper.c
+++ b/userland/libc/ctype/toupper.c
@@ -1,7 +1,8 @@
#include <ctype.h>
int toupper(int c) {
- if (c >= 'a' && c <= 'z')
+ if (c >= 'a' && c <= 'z') {
return c - 'a' + 'A';
+ }
return c;
}
diff --git a/userland/libc/dirent/readdir.c b/userland/libc/dirent/readdir.c
index 9a9f8fa..a7f0d66 100644
--- a/userland/libc/dirent/readdir.c
+++ b/userland/libc/dirent/readdir.c
@@ -18,10 +18,12 @@ struct dirent *readdir(DIR *dir) {
size_t offset = dir->dir_num * sizeof(struct dirent);
int rc;
if (-1 == (rc = pread(dir->fd, &dir->internal_direntry, sizeof(struct dirent),
- offset)))
+ offset))) {
return NULL;
- if (rc < (int)sizeof(struct dirent))
+ }
+ if (rc < (int)sizeof(struct dirent)) {
return NULL;
+ }
dir->dir_num++;
return &(dir->internal_direntry);
diff --git a/userland/libc/dirent/scandir.c b/userland/libc/dirent/scandir.c
index 3ac040a..11f23a9 100644
--- a/userland/libc/dirent/scandir.c
+++ b/userland/libc/dirent/scandir.c
@@ -70,12 +70,14 @@ void scandir_sane_free(struct dirent **namelist) {
int scandir(const char *dir, struct dirent ***namelist,
int (*sel)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **)) {
- if (!compar)
+ if (!compar) {
compar = nop_compar;
+ }
DIR *d = opendir(dir);
- if (!d)
+ if (!d) {
return -1;
+ }
struct dirent **list = NULL;
struct dirent *e;
int rc = 0;
diff --git a/userland/libc/fcntl/open.c b/userland/libc/fcntl/open.c
index 357d826..1e8781a 100644
--- a/userland/libc/fcntl/open.c
+++ b/userland/libc/fcntl/open.c
@@ -1,6 +1,6 @@
#include <fcntl.h>
-#include <syscall.h>
#include <stdarg.h>
+#include <syscall.h>
int open(const char *file, int flags, ...) {
mode_t mode = 0;
diff --git a/userland/libc/include/assert.h b/userland/libc/include/assert.h
index a009e5f..c35845e 100644
--- a/userland/libc/include/assert.h
+++ b/userland/libc/include/assert.h
@@ -1,10 +1,10 @@
#ifndef ASSERT_H
#define ASSERT_H
-#define assert(expr) \
+#define assert(expr) \
{ \
if (!(expr)) \
- aFailed(__FILE__, __LINE__); \
+ aFailed(__FILE__, __LINE__); \
}
void aFailed(char *f, int l);
#endif
diff --git a/userland/libc/include/math.h b/userland/libc/include/math.h
index 7168a5d..3590caa 100644
--- a/userland/libc/include/math.h
+++ b/userland/libc/include/math.h
@@ -1,16 +1,16 @@
#define max(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
-#if 100*__GNUC__+__GNUC_MINOR__ >= 303
-#define NAN __builtin_nanf("")
-#define INFINITY __builtin_inff()
+#if 100 * __GNUC__ + __GNUC_MINOR__ >= 303
+#define NAN __builtin_nanf("")
+#define INFINITY __builtin_inff()
#else
-#define NAN (0.0f/0.0f)
-#define INFINITY 1e40f
+#define NAN (0.0f / 0.0f)
+#define INFINITY 1e40f
#endif
#define HUGE_VALF INFINITY
-#define HUGE_VAL ((double)INFINITY)
+#define HUGE_VAL ((double)INFINITY)
#define HUGE_VALL ((long double)INFINITY)
double ldexp(double x, int exp);
diff --git a/userland/libc/include/pty.h b/userland/libc/include/pty.h
index b8ce978..e5de5a3 100644
--- a/userland/libc/include/pty.h
+++ b/userland/libc/include/pty.h
@@ -1,6 +1,6 @@
#ifndef PTY_H
#define PTY_H
int openpty(int *amaster, int *aslave, char *name,
- /*const struct termios*/ void *termp,
- /*const struct winsize*/ void *winp);
+ /*const struct termios*/ void *termp,
+ /*const struct winsize*/ void *winp);
#endif
diff --git a/userland/libc/include/setjmp.h b/userland/libc/include/setjmp.h
index ea15cf3..ec7e23c 100644
--- a/userland/libc/include/setjmp.h
+++ b/userland/libc/include/setjmp.h
@@ -2,9 +2,9 @@
#define SETJMP_H
typedef unsigned long __jmp_buf[6];
typedef struct __jmp_buf_tag {
- __jmp_buf __jb;
- unsigned long __fl;
- unsigned long __ss[128/sizeof(long)];
+ __jmp_buf __jb;
+ unsigned long __fl;
+ unsigned long __ss[128 / sizeof(long)];
} jmp_buf[1];
typedef jmp_buf sigjmp_buf;
diff --git a/userland/libc/include/sys/sendfile.h b/userland/libc/include/sys/sendfile.h
index 5e83999..6fdd21b 100644
--- a/userland/libc/include/sys/sendfile.h
+++ b/userland/libc/include/sys/sendfile.h
@@ -1,7 +1,6 @@
-#include <stdint.h>
-#include <typedefs.h>
#include <stddef.h>
+#include <stdint.h>
#include <sys/types.h>
+#include <typedefs.h>
-u32 sendfile(int out_fd, int in_fd, off_t *offset, size_t count,
- int *error_rc);
+u32 sendfile(int out_fd, int in_fd, off_t *offset, size_t count, int *error_rc);
diff --git a/userland/libc/include/tb/sb.h b/userland/libc/include/tb/sb.h
index 8493997..7832015 100644
--- a/userland/libc/include/tb/sb.h
+++ b/userland/libc/include/tb/sb.h
@@ -22,8 +22,7 @@ int sb_isempty(const struct sb *ctx);
int sb_append_char(struct sb *ctx, char c);
int sb_delete_right(struct sb *ctx, size_t n);
int sb_append(struct sb *ctx, const char *s);
-int sb_append_buffer(struct sb *ctx, const char *buffer,
- size_t length);
+int sb_append_buffer(struct sb *ctx, const char *buffer, size_t length);
int sb_append_sv(struct sb *ctx, struct sv sv);
int sb_prepend_sv(struct sb *ctx, struct sv sv);
int sb_prepend_buffer(struct sb *ctx, const char *buffer, size_t length);
diff --git a/userland/libc/isspace.c b/userland/libc/isspace.c
index 9ba2766..a922d91 100644
--- a/userland/libc/isspace.c
+++ b/userland/libc/isspace.c
@@ -1,5 +1,5 @@
#include <ctype.h>
int isspace(int c) {
- return c == ' ' || (unsigned)c-'\t' < 5;
+ return c == ' ' || (unsigned)c - '\t' < 5;
}
diff --git a/userland/libc/libgen/basename.c b/userland/libc/libgen/basename.c
index a0a8adb..64a533d 100644
--- a/userland/libc/libgen/basename.c
+++ b/userland/libc/libgen/basename.c
@@ -19,18 +19,21 @@ char *basename_slash_return_value = "/";
char *basename(char *path) {
// If path is a null pointer or points to an empty string, basename()
// shall return a pointer to the string ".".
- if (NULL == path || '\0' == *path)
+ if (NULL == path || '\0' == *path) {
return basename_empty_return_value;
+ }
char *start = path;
// Move the string to the end
for (; *path; path++)
;
- if (start == path)
+ if (start == path) {
return start;
+ }
path--;
- if ('/' == *path) // Trailing slash
+ if ('/' == *path) { // Trailing slash
*path = '\0';
+ }
// Loop until next slash is found
for (; path != start && '/' != *path; path--)
;
@@ -39,7 +42,8 @@ char *basename(char *path) {
// pointed to by path is exactly "//", it is implementation-defined whether
//'/' or "//" is returned.
path++;
- if ('\0' == *path)
+ if ('\0' == *path) {
return basename_slash_return_value;
+ }
return path;
}
diff --git a/userland/libc/libgen/dirname.c b/userland/libc/libgen/dirname.c
index fb3c813..feaf784 100644
--- a/userland/libc/libgen/dirname.c
+++ b/userland/libc/libgen/dirname.c
@@ -5,18 +5,21 @@ char *dirname_slash_return_value = "/";
char *dirname(char *path) {
// If path is a null pointer or points to an empty string,
// dirname() shall return a pointer to the string "."
- if (!path)
+ if (!path) {
return dirname_empty_return_value;
- if ('\0' == *path)
+ }
+ if ('\0' == *path) {
return dirname_empty_return_value;
+ }
char *start = path;
for (; *path; path++)
;
path--;
if ('/' == *path) {
- if (start == path)
+ if (start == path) {
return path;
+ }
path--;
}
@@ -24,11 +27,13 @@ char *dirname(char *path) {
;
// If path does not contain a '/', then dirname() shall return a pointer to
// the string ".".
- if ('/' != *path)
+ if ('/' != *path) {
return dirname_empty_return_value;
+ }
- if (path == start)
+ if (path == start) {
return dirname_slash_return_value;
+ }
*path = '\0';
path--;
@@ -36,8 +41,9 @@ char *dirname(char *path) {
for (; path != start && '/' != *path; path--)
;
- if ('/' != *path)
+ if ('/' != *path) {
return dirname_empty_return_value;
+ }
path++;
return path;
diff --git a/userland/libc/malloc/malloc.h b/userland/libc/malloc/malloc.h
index 596dbe5..d6a6ab7 100644
--- a/userland/libc/malloc/malloc.h
+++ b/userland/libc/malloc/malloc.h
@@ -1,7 +1,7 @@
#ifndef MALLOC_H
#define MALLOC_H
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
void *malloc(size_t s);
void *calloc(size_t nelem, size_t elsize);
diff --git a/userland/libc/memset.c b/userland/libc/memset.c
index 51910e9..6baa3ca 100644
--- a/userland/libc/memset.c
+++ b/userland/libc/memset.c
@@ -7,8 +7,9 @@ void *memset(void *s, int c, size_t n) {
// s.
unsigned char *p = s;
- for (; n > 0; n--, p++)
+ for (; n > 0; n--, p++) {
*p = (unsigned char)c;
+ }
// The memset() function shall return s
return s;
diff --git a/userland/libc/pty.c b/userland/libc/pty.c
index 17b91de..d64e212 100644
--- a/userland/libc/pty.c
+++ b/userland/libc/pty.c
@@ -2,14 +2,14 @@
#include "syscall.h"
int openpty(int *amaster, int *aslave, char *name,
- /*const struct termios*/ void *termp,
- /*const struct winsize*/ void *winp) {
- SYS_OPENPTY_PARAMS args = {
- .amaster = amaster,
- .aslave = aslave,
- .name = name,
- .termp = termp,
- .winp = winp,
- };
- return syscall(SYS_OPENPTY, &args, 0, 0, 0, 0);
+ /*const struct termios*/ void *termp,
+ /*const struct winsize*/ void *winp) {
+ SYS_OPENPTY_PARAMS args = {
+ .amaster = amaster,
+ .aslave = aslave,
+ .name = name,
+ .termp = termp,
+ .winp = winp,
+ };
+ return syscall(SYS_OPENPTY, &args, 0, 0, 0, 0);
}
diff --git a/userland/libc/signal/sigaction.c b/userland/libc/signal/sigaction.c
index 1ff22a7..97ba6ed 100644
--- a/userland/libc/signal/sigaction.c
+++ b/userland/libc/signal/sigaction.c
@@ -1,7 +1,6 @@
#include <signal.h>
#include <syscall.h>
-int sigaction(int sig, const struct sigaction *act,
- struct sigaction *oact) {
- RC_ERRNO(syscall(SYS_SIGACTION, sig, act, oact, 0,0))
+int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
+ RC_ERRNO(syscall(SYS_SIGACTION, sig, act, oact, 0, 0))
}
diff --git a/userland/libc/stdio/feof.c b/userland/libc/stdio/feof.c
index 7f46301..91e7e56 100644
--- a/userland/libc/stdio/feof.c
+++ b/userland/libc/stdio/feof.c
@@ -1,5 +1,5 @@
#include <stdio.h>
int feof(FILE *stream) {
- return stream->is_eof;
+ return stream->is_eof;
}
diff --git a/userland/libc/stdio/ferror.c b/userland/libc/stdio/ferror.c
index 8cb46cf..5049db8 100644
--- a/userland/libc/stdio/ferror.c
+++ b/userland/libc/stdio/ferror.c
@@ -1,5 +1,5 @@
#include <stdio.h>
int ferror(FILE *stream) {
- return stream->has_error;
+ return stream->has_error;
}
diff --git a/userland/libc/stdio/fflush.c b/userland/libc/stdio/fflush.c
index 1cadc72..8bfd16d 100644
--- a/userland/libc/stdio/fflush.c
+++ b/userland/libc/stdio/fflush.c
@@ -1,6 +1,6 @@
+#include <errno.h>
#include <stdio.h>
#include <syscall.h>
-#include <errno.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html
int fflush(FILE *stream) {
diff --git a/userland/libc/stdio/fgetc.c b/userland/libc/stdio/fgetc.c
index afa299f..dc7af77 100644
--- a/userland/libc/stdio/fgetc.c
+++ b/userland/libc/stdio/fgetc.c
@@ -8,13 +8,16 @@ int fgetc(FILE *stream) {
return stream->buffered_char;
}
char c;
- if (1 == fread(&c, 1, 1, stream))
+ if (1 == fread(&c, 1, 1, stream)) {
return (int)c;
+ }
// FIXME: Should use feof and ferror
- if (stream->has_error)
+ if (stream->has_error) {
return EOF;
- if (stream->is_eof)
+ }
+ if (stream->is_eof) {
return EOF;
+ }
// How did we get here?
assert(0);
return EOF;
diff --git a/userland/libc/stdio/fgets.c b/userland/libc/stdio/fgets.c
index 8e21501..acc89a0 100644
--- a/userland/libc/stdio/fgets.c
+++ b/userland/libc/stdio/fgets.c
@@ -4,13 +4,16 @@ char *fgets(char *s, int n, FILE *stream) {
for (int i = 0; i < n; i++) {
char c;
fread(&c, 1, 1, stream);
- if (stream->has_error)
+ if (stream->has_error) {
return NULL;
- if (stream->is_eof)
+ }
+ if (stream->is_eof) {
return NULL;
+ }
s[i] = c;
- if (c == '\n')
+ if (c == '\n') {
break;
+ }
}
return s;
}
diff --git a/userland/libc/stdio/fileno.c b/userland/libc/stdio/fileno.c
index 246cc51..bdf9332 100644
--- a/userland/libc/stdio/fileno.c
+++ b/userland/libc/stdio/fileno.c
@@ -1,5 +1,5 @@
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html
// The fileno() function shall return the integer file descriptor associated
diff --git a/userland/libc/stdio/fputc.c b/userland/libc/stdio/fputc.c
index 7c8fa7c..c41ffa4 100644
--- a/userland/libc/stdio/fputc.c
+++ b/userland/libc/stdio/fputc.c
@@ -1,7 +1,8 @@
#include <stdio.h>
int fputc(int c, FILE *stream) {
- if (fwrite(&c, 1, 1, stream) > 0)
+ if (fwrite(&c, 1, 1, stream) > 0) {
return c;
+ }
return EOF;
}
diff --git a/userland/libc/stdio/fputs.c b/userland/libc/stdio/fputs.c
index 1b70c66..5570693 100644
--- a/userland/libc/stdio/fputs.c
+++ b/userland/libc/stdio/fputs.c
@@ -2,8 +2,10 @@
int fputs(const char *s, FILE *stream) {
const char *b = s;
- for (; *s; s++)
- if (0 == fwrite(s, 1, 1, stream))
+ for (; *s; s++) {
+ if (0 == fwrite(s, 1, 1, stream)) {
return EOF;
+ }
+ }
return s - b;
}
diff --git a/userland/libc/stdio/fscanf.c b/userland/libc/stdio/fscanf.c
index 4af79f9..f8803fc 100644
--- a/userland/libc/stdio/fscanf.c
+++ b/userland/libc/stdio/fscanf.c
@@ -1,5 +1,5 @@
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
int fscanf(FILE *stream, const char *format, ...) {
va_list ap;
diff --git a/userland/libc/stdio/getchar.c b/userland/libc/stdio/getchar.c
index dad2263..e7991cd 100644
--- a/userland/libc/stdio/getchar.c
+++ b/userland/libc/stdio/getchar.c
@@ -1,4 +1,6 @@
#include <stdio.h>
// The getchar() function shall be equivalent to getc(stdin).
-int getchar(void) { return fgetc(stdin); }
+int getchar(void) {
+ return fgetc(stdin);
+}
diff --git a/userland/libc/stdio/open_memstream.c b/userland/libc/stdio/open_memstream.c
index b129cb6..b7ea70b 100644
--- a/userland/libc/stdio/open_memstream.c
+++ b/userland/libc/stdio/open_memstream.c
@@ -35,8 +35,9 @@ size_t memstream_write(FILE *fp, const unsigned char *buf, size_t n) {
memcpy(c->buffer + fp->offset_in_file, buf, n);
fp->offset_in_file += n;
- if (fp->offset_in_file > (long)c->buffer_usage)
+ if (fp->offset_in_file > (long)c->buffer_usage) {
c->buffer_usage = fp->offset_in_file;
+ }
return n;
}
@@ -46,8 +47,9 @@ size_t memstream_read(FILE *fp, unsigned char *buf, size_t n) {
n = min(length_left, n);
memcpy(buf, c->buffer + fp->offset_in_file, n);
fp->offset_in_file += n;
- if (0 == n)
+ if (0 == n) {
fp->is_eof = 1;
+ }
return n;
}
@@ -73,8 +75,9 @@ int memstream_seek(FILE *stream, long offset, int whence) {
FILE *open_memstream(char **bufp, size_t *sizep) {
struct Memstream *c = NULL;
FILE *fp = malloc(sizeof(FILE));
- if (!fp)
+ if (!fp) {
return NULL;
+ }
fp->offset_in_file = 0;
fp->buffered_char = 0;
diff --git a/userland/libc/stdio/putc.c b/userland/libc/stdio/putc.c
index a468a95..cb89ed9 100644
--- a/userland/libc/stdio/putc.c
+++ b/userland/libc/stdio/putc.c
@@ -1,3 +1,5 @@
#include <stdio.h>
-int putc(int c, FILE *stream) { return fputc(c, stream);}
+int putc(int c, FILE *stream) {
+ return fputc(c, stream);
+}
diff --git a/userland/libc/stdio/remove.c b/userland/libc/stdio/remove.c
index 39f8af2..374be58 100644
--- a/userland/libc/stdio/remove.c
+++ b/userland/libc/stdio/remove.c
@@ -1,9 +1,9 @@
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
extern int errno;
int remove(const char *path) {
- (void)path;
+ (void)path;
// FIXME
errno = ENAMETOOLONG;
return -1;
diff --git a/userland/libc/stdio/rename.c b/userland/libc/stdio/rename.c
index a02cacb..676fd8c 100644
--- a/userland/libc/stdio/rename.c
+++ b/userland/libc/stdio/rename.c
@@ -5,5 +5,5 @@ int rename(const char *old, const char *new) {
(void)old;
(void)new;
assert(0); // TODO: Implement
- return 0;
+ return 0;
}
diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c
index e497167..4620df3 100644
--- a/userland/libc/stdio/stdin.c
+++ b/userland/libc/stdio/stdin.c
@@ -36,8 +36,9 @@ size_t write_fd(FILE *f, const unsigned char *s, size_t l) {
size_t non_cache_read_fd(FILE *f, unsigned char *s, size_t l) {
int rc = read(f->fd, s, l);
- if (rc == 0)
+ if (rc == 0) {
f->is_eof = 1;
+ }
if (rc == -1) {
f->has_error = 1;
return 0;
@@ -46,8 +47,9 @@ size_t non_cache_read_fd(FILE *f, unsigned char *s, size_t l) {
}
size_t read_fd(FILE *f, unsigned char *s, size_t l) {
- if (0 == l)
+ if (0 == l) {
return 0;
+ }
// Skip using cache if the length being requested if longer than or
// equal to the cache block size. This avoids doing a bunch of extra
diff --git a/userland/libc/stdio/tmpfile.c b/userland/libc/stdio/tmpfile.c
index cee6e0a..9d3fb92 100644
--- a/userland/libc/stdio/tmpfile.c
+++ b/userland/libc/stdio/tmpfile.c
@@ -1,9 +1,9 @@
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
FILE *tmpfile(void) {
- // TODO
- printf("TODO: Implement tmpfile()\n");
- assert(0);
- return NULL;
+ // TODO
+ printf("TODO: Implement tmpfile()\n");
+ assert(0);
+ return NULL;
}
diff --git a/userland/libc/stdio/ungetc.c b/userland/libc/stdio/ungetc.c
index 3b93b70..18e5a21 100644
--- a/userland/libc/stdio/ungetc.c
+++ b/userland/libc/stdio/ungetc.c
@@ -1,8 +1,9 @@
#include <stdio.h>
int ungetc(int c, FILE *stream) {
- if (stream->has_buffered_char)
+ if (stream->has_buffered_char) {
return EOF;
+ }
stream->buffered_char = c;
stream->has_buffered_char = 1;
fseek(stream, -1, SEEK_CUR);
diff --git a/userland/libc/stdio/vfprintf.c b/userland/libc/stdio/vfprintf.c
index d384c1d..35a7c9a 100644
--- a/userland/libc/stdio/vfprintf.c
+++ b/userland/libc/stdio/vfprintf.c
@@ -32,8 +32,9 @@ int fprint_num(FILE *f, long long n, int base, char *char_set, int prefix,
str[i] = char_set[0];
i++;
} else {
- for (; n != 0 && i < 32; i++, n /= base)
+ for (; n != 0 && i < 32; i++, n /= base) {
str[i] = char_set[(n % base)];
+ }
}
if (is_signed) {
@@ -45,16 +46,19 @@ int fprint_num(FILE *f, long long n, int base, char *char_set, int prefix,
int orig_i = i;
if (!right_padding) {
- for (; prefix - orig_i > 0; prefix--)
+ for (; prefix - orig_i > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
- for (i--; i >= 0; i--)
+ for (i--; i >= 0; i--) {
FILE_WRITE(f, &(str[i]), 1, &c);
+ }
if (right_padding) {
- for (; prefix - orig_i > 0; prefix--)
+ for (; prefix - orig_i > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
return c;
}
@@ -82,16 +86,19 @@ int print_string(FILE *f, const char *s, int *rc, int prefix, int right_padding,
char t = ' ';
int c = 0;
if (!right_padding) {
- if (prefix)
+ if (prefix) {
assert(-1 == precision); // FIXME: Is this correct?
- for (; prefix - l > 0; prefix--)
+ }
+ for (; prefix - l > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
int bl = precision;
for (; *s; s++, (*rc)++) {
if (precision != -1) {
- if (0 == bl)
+ if (0 == bl) {
break;
+ }
bl--;
}
int r = 0;
@@ -99,8 +106,9 @@ int print_string(FILE *f, const char *s, int *rc, int prefix, int right_padding,
}
if (right_padding) {
assert(-1 == precision); // FIXME: Is this correct?
- for (; prefix - l > 0; prefix--)
+ for (; prefix - l > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
(*rc) += c;
return 0;
@@ -110,8 +118,9 @@ int parse_precision(const char **fmt) {
const char *s = *fmt;
int rc = 0;
for (int i = 0;; i++, s++) {
- if ('\0' == *s)
+ if ('\0' == *s) {
break;
+ }
const char c = *s;
if ('*' == c) {
assert(i == 0);
@@ -149,8 +158,9 @@ int vfprintf(FILE *f, const char *fmt, va_list ap) {
continue;
}
- if ('\0' == *s)
+ if ('\0' == *s) {
break;
+ }
switch (*s) {
case '.':
@@ -158,14 +168,16 @@ int vfprintf(FILE *f, const char *fmt, va_list ap) {
assert('\0' != *s);
precision = parse_precision(&s);
assert('\0' != *s);
- if (-1 == precision)
+ if (-1 == precision) {
precision = va_arg(ap, int);
+ }
cont = 1;
break;
case '0':
prefix *= 10;
- if (0 == prefix)
+ if (0 == prefix) {
zero_padding = 1;
+ }
cont = 1;
break;
case '-':
@@ -221,13 +233,15 @@ int vfprintf(FILE *f, const char *fmt, va_list ap) {
char *a = va_arg(ap, char *);
if (!a) {
if (-1 ==
- print_string(f, "(NULL)", &rc, prefix, right_padding, precision))
+ print_string(f, "(NULL)", &rc, prefix, right_padding, precision)) {
return -1;
+ }
cont = 0;
break;
}
- if (-1 == print_string(f, a, &rc, prefix, right_padding, precision))
+ if (-1 == print_string(f, a, &rc, prefix, right_padding, precision)) {
return -1;
+ }
cont = 0;
break;
}
diff --git a/userland/libc/stdio/vprintf.c b/userland/libc/stdio/vprintf.c
index 8a8dc33..c06e9f9 100644
--- a/userland/libc/stdio/vprintf.c
+++ b/userland/libc/stdio/vprintf.c
@@ -1,3 +1,5 @@
#include <stdio.h>
-int vprintf(const char *format, va_list ap) { return vdprintf(1, format, ap); }
+int vprintf(const char *format, va_list ap) {
+ return vdprintf(1, format, ap);
+}
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];
diff --git a/userland/libc/string/memchr.c b/userland/libc/string/memchr.c
index cef3bc2..0d581f4 100644
--- a/userland/libc/string/memchr.c
+++ b/userland/libc/string/memchr.c
@@ -4,7 +4,7 @@ void *memchr(const void *s, int c, size_t n) {
const char *p = s;
for (; n > 0; n--, p++) {
if (*p == c) {
- return (void*)p;
+ return (void *)p;
}
}
return NULL;
diff --git a/userland/libc/string/memcmp.c b/userland/libc/string/memcmp.c
index 01109b8..157189f 100644
--- a/userland/libc/string/memcmp.c
+++ b/userland/libc/string/memcmp.c
@@ -3,9 +3,11 @@
int memcmp(const void *s1, const void *s2, size_t n) {
int return_value = 0;
- for (uint32_t i = 0; i < n; i++)
- if (((unsigned char *)(s1))[i] != ((unsigned char *)(s2))[i])
+ for (uint32_t i = 0; i < n; i++) {
+ if (((unsigned char *)(s1))[i] != ((unsigned char *)(s2))[i]) {
return_value++;
+ }
+ }
return return_value;
}
diff --git a/userland/libc/string/memcpy.c b/userland/libc/string/memcpy.c
index 7a9f01e..65f646d 100644
--- a/userland/libc/string/memcpy.c
+++ b/userland/libc/string/memcpy.c
@@ -4,15 +4,19 @@ void *memcpy(void *dest, const void *src, uint32_t n) {
unsigned char *d = dest;
const unsigned char *s = src;
- for (; n >= 8; n -= 8, d += 8, s += 8)
+ for (; n >= 8; n -= 8, d += 8, s += 8) {
*(uint64_t *)d = *(uint64_t *)s;
+ }
- for (; n >= 4; n -= 4, d += 4, s += 4)
+ for (; n >= 4; n -= 4, d += 4, s += 4) {
*(uint32_t *)d = *(uint32_t *)s;
+ }
- for (; n >= 2; n -= 2, d += 2, s += 2)
+ for (; n >= 2; n -= 2, d += 2, s += 2) {
*(uint16_t *)d = *(uint16_t *)s;
- for (; n; n--)
+ }
+ for (; n; n--) {
*d++ = *s++;
+ }
return dest;
}
diff --git a/userland/libc/string/sscanf.c b/userland/libc/string/sscanf.c
index e1ede63..8a3ed0e 100644
--- a/userland/libc/string/sscanf.c
+++ b/userland/libc/string/sscanf.c
@@ -38,8 +38,9 @@ long ftnum(FILE *stream, int base, int *error) {
return 0;
}
for (;;) {
- if (EOF == (c = fgetc(stream)))
+ if (EOF == (c = fgetc(stream))) {
break;
+ }
if (c == '\0') {
ungetc(c, stream);
break;
@@ -69,13 +70,15 @@ int vfscanf(FILE *stream, const char *format, va_list ap) {
for (; *format; format++) {
if (*format != '%' && !cont) {
char c;
- if (isspace(*format))
+ if (isspace(*format)) {
continue;
+ }
if (EOF == (c = fgetc(stream))) {
break;
}
- if (*format == c) // TODO: Make sure this is the correct behaviour
+ if (*format == c) { // TODO: Make sure this is the correct behaviour
continue;
+ }
// TODO: Make sure this is the correct behaviour
errno = EINVAL;
assert(0);
@@ -164,8 +167,9 @@ size_t sscanf_read(FILE *f, unsigned char *s, size_t l) {
s++;
r++;
}
- if (!(*(c->s + c->offset)))
+ if (!(*(c->s + c->offset))) {
f->is_eof = 1;
+ }
/*
memcpy(s, c->s, l);
c->s += l;*/
diff --git a/userland/libc/string/strcasecmp.c b/userland/libc/string/strcasecmp.c
index 6420dbf..399ebc2 100644
--- a/userland/libc/string/strcasecmp.c
+++ b/userland/libc/string/strcasecmp.c
@@ -7,8 +7,9 @@ int strcasecmp(const char *s1, const char *s2) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; (*s1 || *s2);) {
- if (tolower(*s1) != tolower(*s2))
+ if (tolower(*s1) != tolower(*s2)) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -23,7 +24,8 @@ int strcasecmp(const char *s1, const char *s2) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strchr.c b/userland/libc/string/strchr.c
index 1995547..179e47c 100644
--- a/userland/libc/string/strchr.c
+++ b/userland/libc/string/strchr.c
@@ -2,10 +2,12 @@
char *strchr(const char *s, int c) {
for (; *s; s++) {
- if (*s == (char)c)
- return (char*)s;
+ if (*s == (char)c) {
+ return (char *)s;
+ }
}
- if ((char)c == '\0')
+ if ((char)c == '\0') {
return (char *)s;
+ }
return NULL;
}
diff --git a/userland/libc/string/strcmp.c b/userland/libc/string/strcmp.c
index 368b8fb..b07f023 100644
--- a/userland/libc/string/strcmp.c
+++ b/userland/libc/string/strcmp.c
@@ -7,8 +7,9 @@ int strcmp(const char *s1, const char *s2) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; *s1 || *s2;) {
- if (*s1 != *s2)
+ if (*s1 != *s2) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -23,7 +24,8 @@ int strcmp(const char *s1, const char *s2) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strcspn.c b/userland/libc/string/strcspn.c
index 2ad38d5..fb5fe50 100644
--- a/userland/libc/string/strcspn.c
+++ b/userland/libc/string/strcspn.c
@@ -6,7 +6,7 @@ size_t strcspn(const char *s1, const char *s2) {
for (const char *t = s2; *t; t++) {
if (*s1 == *s2) {
r++;
- break;
+ break;
}
}
}
diff --git a/userland/libc/string/strdup.c b/userland/libc/string/strdup.c
index 9e22f94..ead535a 100644
--- a/userland/libc/string/strdup.c
+++ b/userland/libc/string/strdup.c
@@ -8,8 +8,9 @@
char *strdup(const char *s) {
size_t l = strlen(s);
char *r = malloc(l + 1);
- if (!r)
+ if (!r) {
return NULL;
+ }
strcpy(r, s);
return r;
}
diff --git a/userland/libc/string/strlcpy.c b/userland/libc/string/strlcpy.c
index a2d3dd9..041522b 100644
--- a/userland/libc/string/strlcpy.c
+++ b/userland/libc/string/strlcpy.c
@@ -7,12 +7,14 @@ size_t *strlcpy(char *s1, const char *s2, size_t n) {
size_t tmp_n = n;
const char *os2 = s2;
for (; tmp_n; tmp_n--) {
- if ((*s1++ = *s2++) == '\0')
+ if ((*s1++ = *s2++) == '\0') {
break;
+ }
}
if (tmp_n == 0) {
- if (n != 0)
+ if (n != 0) {
*s1 = '\0'; /* NUL-terminate s1 */
+ }
while (*s2++)
;
}
diff --git a/userland/libc/string/strncasecmp.c b/userland/libc/string/strncasecmp.c
index c635a03..8a7768c 100644
--- a/userland/libc/string/strncasecmp.c
+++ b/userland/libc/string/strncasecmp.c
@@ -1,6 +1,6 @@
-#include <strings.h>
#include <ctype.h>
#include <stddef.h>
+#include <strings.h>
int strncasecmp(const char *s1, const char *s2, size_t n) {
// The strcmp() function shall compare the string pointed to by s1
@@ -8,8 +8,9 @@ int strncasecmp(const char *s1, const char *s2, size_t n) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; (*s1 || *s2) && n > 0; n--) {
- if (tolower(*s1) != tolower(*s2))
+ if (tolower(*s1) != tolower(*s2)) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -24,7 +25,8 @@ int strncasecmp(const char *s1, const char *s2, size_t n) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strncmp.c b/userland/libc/string/strncmp.c
index fd46189..3d6383b 100644
--- a/userland/libc/string/strncmp.c
+++ b/userland/libc/string/strncmp.c
@@ -6,8 +6,9 @@ int strncmp(const char *s1, const char *s2, size_t n) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; (*s1 || *s2) && n > 0; n--) {
- if (*s1 != *s2)
+ if (*s1 != *s2) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -22,7 +23,8 @@ int strncmp(const char *s1, const char *s2, size_t n) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strncpy.c b/userland/libc/string/strncpy.c
index 0e88c63..fb89d38 100644
--- a/userland/libc/string/strncpy.c
+++ b/userland/libc/string/strncpy.c
@@ -4,10 +4,12 @@ char *strncpy(char *s1, const char *s2, size_t n) {
char *rc = s1;
for (; n > 0; s1++, s2++, n--) {
*s1 = *s2;
- if (!*s2)
+ if (!*s2) {
break;
+ }
}
- for (; n > 0; n--,s1++)
+ for (; n > 0; n--, s1++) {
*s1 = '\0';
+ }
return rc;
}
diff --git a/userland/libc/string/strndup.c b/userland/libc/string/strndup.c
index 22d6303..3240d97 100644
--- a/userland/libc/string/strndup.c
+++ b/userland/libc/string/strndup.c
@@ -1,7 +1,7 @@
+#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
// The strndup() function shall be equivalent to the strdup() function,
// duplicating the provided s in a new block of memory allocated as if
@@ -16,8 +16,9 @@ char *strndup(const char *s, size_t size) {
size_t l = strlen(s);
size_t real_l = min(l, size);
char *r = malloc(real_l + 1);
- if (!r)
+ if (!r) {
return NULL;
+ }
strlcpy(r, s, real_l);
return r;
}
diff --git a/userland/libc/string/strnlen.c b/userland/libc/string/strnlen.c
index 86df42e..50f907e 100644
--- a/userland/libc/string/strnlen.c
+++ b/userland/libc/string/strnlen.c
@@ -2,8 +2,10 @@
size_t strnlen(const char *s, size_t maxlen) {
size_t i;
- for (i = 0; i < maxlen; i++)
- if (s[i] == 0)
+ for (i = 0; i < maxlen; i++) {
+ if (s[i] == 0) {
break;
+ }
+ }
return i;
}
diff --git a/userland/libc/string/strpbrk.c b/userland/libc/string/strpbrk.c
index 3bb058b..cbe51de 100644
--- a/userland/libc/string/strpbrk.c
+++ b/userland/libc/string/strpbrk.c
@@ -4,7 +4,7 @@ char *strpbrk(const char *s1, const char *s2) {
for (; *s1; s1++) {
for (const char *t = s2; *t; t++) {
if (*s1 == *t) {
- return (char*)s1;
+ return (char *)s1;
}
}
}
diff --git a/userland/libc/string/strrchr.c b/userland/libc/string/strrchr.c
index a44199a..30b625d 100644
--- a/userland/libc/string/strrchr.c
+++ b/userland/libc/string/strrchr.c
@@ -3,10 +3,12 @@
char *strrchr(const char *s, int c) {
char *last = NULL;
for (; *s; s++) {
- if (*s == (char)c)
+ if (*s == (char)c) {
last = (char *)s;
+ }
+ }
+ if ((char)c == '\0') {
+ last = (char *)s;
}
- if ((char)c == '\0')
- last = (char*)s;
return last;
}
diff --git a/userland/libc/string/strspn.c b/userland/libc/string/strspn.c
index 2a7d3ae..d6b1595 100644
--- a/userland/libc/string/strspn.c
+++ b/userland/libc/string/strspn.c
@@ -10,8 +10,9 @@ size_t strspn(const char *s1, const char *s2) {
break;
}
}
- if (!e)
+ if (!e) {
break;
+ }
r++;
}
return r;
diff --git a/userland/libc/string/strstr.c b/userland/libc/string/strstr.c
index 9de0954..4300f24 100644
--- a/userland/libc/string/strstr.c
+++ b/userland/libc/string/strstr.c
@@ -2,8 +2,9 @@
char *strstr(const char *s1, const char *s2) {
// If s2 points to a string with zero length, the function shall return s1.
- if ('\0' == *s2)
- return (char*)s1;
+ if ('\0' == *s2) {
+ return (char *)s1;
+ }
for (; *s1; s1++) {
const char *t1 = s1;
const char *t2 = s2;
@@ -14,8 +15,9 @@ char *strstr(const char *s1, const char *s2) {
break;
}
}
- if (!is_dif)
- return (char*)s1;
+ if (!is_dif) {
+ return (char *)s1;
+ }
}
return NULL;
}
diff --git a/userland/libc/string/strtok.c b/userland/libc/string/strtok.c
index 7b8d0e3..a4a9d0f 100644
--- a/userland/libc/string/strtok.c
+++ b/userland/libc/string/strtok.c
@@ -7,18 +7,20 @@ char *strtok(char *restrict s, const char *restrict sep) {
strtok_s = s;
return strtok(NULL, sep);
}
- if(!strtok_s)
- return NULL;
+ if (!strtok_s) {
+ return NULL;
+ }
char *e = strpbrk(strtok_s, sep);
if (!e) {
- char *r = strtok_s;
- strtok_s = NULL;
+ char *r = strtok_s;
+ strtok_s = NULL;
return r;
}
*e = '\0';
e--;
- for (; *sep; sep++)
+ for (; *sep; sep++) {
e++;
+ }
e++;
char *r = strtok_s;
strtok_s = e;
diff --git a/userland/libc/sys/mman.h b/userland/libc/sys/mman.h
index e3ff734..a915291 100644
--- a/userland/libc/sys/mman.h
+++ b/userland/libc/sys/mman.h
@@ -1,7 +1,7 @@
#ifndef MMAP_H
#define MMAP_H
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
void *mmap(void *addr, size_t length, int prot, int flags, int fd,
size_t offset);
diff --git a/userland/libc/sys/mman/mmap.c b/userland/libc/sys/mman/mmap.c
index b9ad3a2..53c6f77 100644
--- a/userland/libc/sys/mman/mmap.c
+++ b/userland/libc/sys/mman/mmap.c
@@ -1,6 +1,6 @@
-#include <syscall.h>
#include <errno.h>
#include <sys/mman.h>
+#include <syscall.h>
extern int errno;
@@ -14,6 +14,6 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd,
.fd = fd,
.offset = offset,
};
-// return (void*)syscall(SYS_MMAP, &args, 0, 0, 0, 0);
+ // return (void*)syscall(SYS_MMAP, &args, 0, 0, 0, 0);
RC_ERRNO(syscall(SYS_MMAP, &args, 0, 0, 0, 0));
}
diff --git a/userland/libc/sys/mman/munmap.c b/userland/libc/sys/mman/munmap.c
index 940ea46..5750cb4 100644
--- a/userland/libc/sys/mman/munmap.c
+++ b/userland/libc/sys/mman/munmap.c
@@ -2,5 +2,5 @@
#include <syscall.h>
int munmap(void *addr, size_t length) {
- RC_ERRNO(syscall(SYS_MUNMAP, addr, length,0, 0, 0));
+ RC_ERRNO(syscall(SYS_MUNMAP, addr, length, 0, 0, 0));
}
diff --git a/userland/libc/sys/sendfile.c b/userland/libc/sys/sendfile.c
index 818883b..9de931b 100644
--- a/userland/libc/sys/sendfile.c
+++ b/userland/libc/sys/sendfile.c
@@ -1,6 +1,6 @@
+#include <errno.h>
#include <sys/sendfile.h>
#include <syscall.h>
-#include <errno.h>
u32 sendfile(int out_fd, int in_fd, off_t *offset, size_t count,
int *error_rc) {
diff --git a/userland/libc/sys/socket/listen.c b/userland/libc/sys/socket/listen.c
index a3bec10..67cc6ce 100644
--- a/userland/libc/sys/socket/listen.c
+++ b/userland/libc/sys/socket/listen.c
@@ -1,9 +1,9 @@
-#include <sys/socket.h>
#include <stdio.h>
+#include <sys/socket.h>
int listen(int socket, int backlog) {
- (void)socket;
- (void)backlog;
+ (void)socket;
+ (void)backlog;
printf("TODO: Implement listen()\n");
return 0;
}
diff --git a/userland/libc/sys/socket/sendto.c b/userland/libc/sys/socket/sendto.c
index 73437ab..be35ec0 100644
--- a/userland/libc/sys/socket/sendto.c
+++ b/userland/libc/sys/socket/sendto.c
@@ -7,7 +7,7 @@ struct two_args {
};
size_t sendto(int socket, const void *message, size_t length, int flags,
- const struct sockaddr *dest_addr, socklen_t dest_len) {
+ const struct sockaddr *dest_addr, socklen_t dest_len) {
struct two_args extra = {
.a = dest_addr,
.b = dest_len,
diff --git a/userland/libc/sys/time/gettimeofday.c b/userland/libc/sys/time/gettimeofday.c
index e172cf2..3487254 100644
--- a/userland/libc/sys/time/gettimeofday.c
+++ b/userland/libc/sys/time/gettimeofday.c
@@ -1,5 +1,7 @@
#include <sys/time.h>
#include <time.h>
-static int return_tod =0;
-int gettimeofday(struct timeval *tp, void *tzp) {return return_tod++;}
+static int return_tod = 0;
+int gettimeofday(struct timeval *tp, void *tzp) {
+ return return_tod++;
+}
diff --git a/userland/libc/sys/types.h b/userland/libc/sys/types.h
index ffcf281..d9bede0 100644
--- a/userland/libc/sys/types.h
+++ b/userland/libc/sys/types.h
@@ -16,12 +16,12 @@ typedef int dev_t;
typedef unsigned int fsblkcnt_t;
typedef unsigned int fsfilcnt_t;
typedef unsigned int ino_t;
-//typedef unsigned int size_t;
+// typedef unsigned int size_t;
typedef int blksize_t;
typedef int pid_t;
typedef int ssize_t;
-//typedef int clock_t;
+// typedef int clock_t;
typedef int time_t;
#endif
diff --git a/userland/libc/tb/sha1.c b/userland/libc/tb/sha1.c
index 90e4e2a..1f68672 100644
--- a/userland/libc/tb/sha1.c
+++ b/userland/libc/tb/sha1.c
@@ -3,10 +3,10 @@
//
// SPDX-License-Identifier: 0BSD
//
-#include <tb/sha1.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
+#include <tb/sha1.h>
#define SHA1_CONSTANT_H0 0x67452301
#define SHA1_CONSTANT_H1 0xefcdab89
@@ -57,10 +57,11 @@ void pad_sha1_message(uint8_t *M, uint64_t l, uint64_t active_l,
// solution to the equation 'l + 1 + k \cong 448 mod 512'
int k;
uint64_t rest = (active_l + 1) % 512;
- if (rest < 448)
+ if (rest < 448) {
k = 448 - rest;
- else
+ } else {
k = 512 - rest + 448;
+ }
memset(block + ARRAY_NUM(active_l) + 2, 0x0, k / 8);
@@ -90,14 +91,18 @@ uint32_t sha1_f(uint8_t t, uint32_t x, uint32_t y, uint32_t z) {
}
uint32_t sha1_get_k(uint8_t t) {
- if (t <= 19)
+ if (t <= 19) {
return SHA1_CONSTANT_K1;
- if (t <= 39)
+ }
+ if (t <= 39) {
return SHA1_CONSTANT_K2;
- if (t <= 59)
+ }
+ if (t <= 59) {
return SHA1_CONSTANT_K3;
- if (t <= 79)
+ }
+ if (t <= 79) {
return SHA1_CONSTANT_K4;
+ }
return 0;
}
@@ -109,16 +114,18 @@ uint32_t ROTL(uint32_t value, uint8_t shift) {
void add_block(SHA1_CTX *ctx, uint8_t *_block) {
uint32_t *block = (uint32_t *)_block;
- for (size_t i = 0; i < 16; i++)
+ for (size_t i = 0; i < 16; i++) {
block[i] = reverse_32(block[i]);
+ }
uint32_t W[80];
uint32_t a, b, c, d, e;
uint32_t *M = block;
// 1. Prepare the message schedule, {Wt}:
- for (size_t t = 0; t < 16; t++)
+ for (size_t t = 0; t < 16; t++) {
W[t] = M[t];
+ }
for (size_t t = 16; t < 80; t++) {
// ROTL(1)(W(t-3) ^ W(t-8) ^ W(t-16))
@@ -157,14 +164,17 @@ void SHA1_Final(SHA1_CTX *ctx, unsigned char *message_digest) {
add_block(ctx, block);
- if (((ctx->active_len * 8 + 1) % 512) >= 448)
+ if (((ctx->active_len * 8 + 1) % 512) >= 448) {
add_block(ctx, block + BLOCK_BYTES);
+ }
- for (size_t i = 0; i < 5; i++)
+ for (size_t i = 0; i < 5; i++) {
ctx->h[i] = reverse_32(ctx->h[i]);
+ }
- for (size_t i = 0; i < 5; i++)
+ for (size_t i = 0; i < 5; i++) {
memcpy(message_digest + sizeof(uint32_t) * i, &ctx->h[i], sizeof(uint32_t));
+ }
}
void SHA1_Update(SHA1_CTX *ctx, const void *data, uint64_t len) {
@@ -176,8 +186,9 @@ void SHA1_Update(SHA1_CTX *ctx, const void *data, uint64_t len) {
memcpy(ctx->block + ctx->active_len, data, write_len);
ctx->len += write_len;
ctx->active_len += write_len;
- if (BLOCK_BYTES != ctx->active_len)
+ if (BLOCK_BYTES != ctx->active_len) {
return;
+ }
add_block(ctx, ctx->block);
memset(ctx->block, 0, BLOCK_BYTES);
diff --git a/userland/libc/time/gmtime.c b/userland/libc/time/gmtime.c
index 08af482..0b5b09e 100644
--- a/userland/libc/time/gmtime.c
+++ b/userland/libc/time/gmtime.c
@@ -16,7 +16,7 @@ struct tm gmtime_r = {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html
struct tm *gmtime(const time_t *timer) {
- (void)timer;
+ (void)timer;
// TODO: Implement
return &gmtime_r;
}
diff --git a/userland/libc/time/localtime.c b/userland/libc/time/localtime.c
index 8ad74d8..ce15ffb 100644
--- a/userland/libc/time/localtime.c
+++ b/userland/libc/time/localtime.c
@@ -1,22 +1,22 @@
#include <time.h>
- struct tm localtime_r = {
- .tm_sec = 0,
- .tm_min = 0,
- .tm_hour = 0,
- .tm_mday = 0,
- .tm_mon = 0,
- .tm_year = 0,
- .tm_wday = 0,
- .tm_yday = 0,
- .tm_isdst = 0,
- .__tm_gmtoff = 0,
- .__tm_zone = 0,
- };
+struct tm localtime_r = {
+ .tm_sec = 0,
+ .tm_min = 0,
+ .tm_hour = 0,
+ .tm_mday = 0,
+ .tm_mon = 0,
+ .tm_year = 0,
+ .tm_wday = 0,
+ .tm_yday = 0,
+ .tm_isdst = 0,
+ .__tm_gmtoff = 0,
+ .__tm_zone = 0,
+};
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html
struct tm *localtime(const time_t *timer) {
- (void)timer;
+ (void)timer;
// TODO: Implement
return &localtime_r;
}
diff --git a/userland/libc/time/strftime.c b/userland/libc/time/strftime.c
index 30a080d..b6a5f58 100644
--- a/userland/libc/time/strftime.c
+++ b/userland/libc/time/strftime.c
@@ -1,7 +1,7 @@
-#include <time.h>
#include <stddef.h>
+#include <time.h>
-size_t strftime(char *restrict s, size_t maxsize,
- const char *restrict format, const struct tm *restrict timeptr) {
- return 0;
+size_t strftime(char *restrict s, size_t maxsize, const char *restrict format,
+ const struct tm *restrict timeptr) {
+ return 0;
}
diff --git a/userland/libc/time/time.c b/userland/libc/time/time.c
index 9931b71..fa025ce 100644
--- a/userland/libc/time/time.c
+++ b/userland/libc/time/time.c
@@ -3,7 +3,8 @@
time_t time(time_t *tloc) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
- if (tloc)
+ if (tloc) {
*tloc = ts.tv_sec;
+ }
return ts.tv_sec;
}
diff --git a/userland/libc/ubsan.c b/userland/libc/ubsan.c
index 9ac9879..90e2eb4 100644
--- a/userland/libc/ubsan.c
+++ b/userland/libc/ubsan.c
@@ -29,8 +29,8 @@ void __ubsan_handle_sub_overflow(struct OverflowData *data, unsigned long lhs,
ubsan_log("handle_sub_overflow", data->location);
}
-void __ubsan_handle_negate_overflow(struct OverflowData *data, unsigned long lhs,
- unsigned long rhs) {
+void __ubsan_handle_negate_overflow(struct OverflowData *data,
+ unsigned long lhs, unsigned long rhs) {
(void)lhs;
(void)rhs;
ubsan_log("handle_negate_overflow", data->location);
diff --git a/userland/libc/unistd/_exit.c b/userland/libc/unistd/_exit.c
index c6d64be..a6cc645 100644
--- a/userland/libc/unistd/_exit.c
+++ b/userland/libc/unistd/_exit.c
@@ -5,4 +5,6 @@
// stackoverflow answer says that it does not usually matter. So lets
// hope that is the case.
// https://stackoverflow.com/a/5423108
-void _exit(int status) { syscall(SYS_EXIT, (void *)status, 0, 0, 0, 0); }
+void _exit(int status) {
+ syscall(SYS_EXIT, (void *)status, 0, 0, 0, 0);
+}
diff --git a/userland/libc/unistd/chdir.c b/userland/libc/unistd/chdir.c
index 90b30ae..61372c0 100644
--- a/userland/libc/unistd/chdir.c
+++ b/userland/libc/unistd/chdir.c
@@ -1,4 +1,6 @@
-#include <unistd.h>
#include <syscall.h>
+#include <unistd.h>
-int chdir(const char *path) { RC_ERRNO(syscall(SYS_CHDIR, path, 0, 0, 0, 0)); }
+int chdir(const char *path) {
+ RC_ERRNO(syscall(SYS_CHDIR, path, 0, 0, 0, 0));
+}
diff --git a/userland/libc/unistd/getpid.c b/userland/libc/unistd/getpid.c
index 8aeef10..47f9e71 100644
--- a/userland/libc/unistd/getpid.c
+++ b/userland/libc/unistd/getpid.c
@@ -1,7 +1,7 @@
-#include <unistd.h>
-#include <syscall.h>
#include <sys/types.h>
+#include <syscall.h>
+#include <unistd.h>
pid_t getpid(void) {
- return s_syscall(SYS_GETPID);
+ return s_syscall(SYS_GETPID);
}
diff --git a/userland/libc/unistd/isatty.c b/userland/libc/unistd/isatty.c
index d8b08c3..55cf4e7 100644
--- a/userland/libc/unistd/isatty.c
+++ b/userland/libc/unistd/isatty.c
@@ -1,11 +1,12 @@
+#include <errno.h>
#include <syscall.h>
#include <unistd.h>
-#include <errno.h>
int isatty(int fd) {
int rc = syscall(SYS_ISATTY, fd, 0, 0, 0, 0);
- if (1 == rc)
+ if (1 == rc) {
return rc;
+ }
errno = -rc;
return 0;
}
diff --git a/userland/libc/unistd/msleep.c b/userland/libc/unistd/msleep.c
index 0b016c6..1f70a7b 100644
--- a/userland/libc/unistd/msleep.c
+++ b/userland/libc/unistd/msleep.c
@@ -1,6 +1,8 @@
// Not standard, but it feels like it should be.
+#include <stdint.h>
#include <syscall.h>
#include <unistd.h>
-#include <stdint.h>
-void msleep(uint32_t ms) { syscall(SYS_MSLEEP, (void *)ms, 0, 0, 0, 0); }
+void msleep(uint32_t ms) {
+ syscall(SYS_MSLEEP, (void *)ms, 0, 0, 0, 0);
+}
diff --git a/userland/libc/unistd/unlink.c b/userland/libc/unistd/unlink.c
index 7d7aa1c..f26539a 100644
--- a/userland/libc/unistd/unlink.c
+++ b/userland/libc/unistd/unlink.c
@@ -1,5 +1,5 @@
-#include <unistd.h>
#include <stdio.h>
+#include <unistd.h>
int unlink(const char *path) {
// TODO
diff --git a/userland/libc/unistd/uptime.c b/userland/libc/unistd/uptime.c
index 090a0e5..5a0654f 100644
--- a/userland/libc/unistd/uptime.c
+++ b/userland/libc/unistd/uptime.c
@@ -3,4 +3,6 @@
#include <syscall.h>
#include <unistd.h>
-uint32_t uptime(void) { return syscall(SYS_UPTIME, 0, 0, 0, 0, 0); }
+uint32_t uptime(void) {
+ return syscall(SYS_UPTIME, 0, 0, 0, 0, 0);
+}
diff --git a/userland/libc/unistd/write.c b/userland/libc/unistd/write.c
index 0dd1824..82e29fd 100644
--- a/userland/libc/unistd/write.c
+++ b/userland/libc/unistd/write.c
@@ -1,6 +1,6 @@
+#include <errno.h>
#include <syscall.h>
#include <unistd.h>
-#include <errno.h>
int write(int fd, const char *buf, size_t count) {
RC_ERRNO(syscall(SYS_WRITE, fd, buf, count, 0, 0));