From 46527b72d7cfbeee163c1009e27805061fcddf09 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Jun 2019 11:49:03 +0200 Subject: [PATCH] LibC: Run clang-format on everything. --- LibC/SharedBuffer.cpp | 6 ++-- LibC/arpa/inet.cpp | 4 +-- LibC/assert.cpp | 6 ++-- LibC/crt0.cpp | 1 - LibC/ctype.cpp | 9 +++--- LibC/dirent.cpp | 6 ++-- LibC/dlfcn.cpp | 7 ++--- LibC/fcntl.cpp | 3 +- LibC/getopt.cpp | 20 ++++++------- LibC/grp.cpp | 5 ++-- LibC/ioctl.cpp | 4 +-- LibC/locale.cpp | 3 +- LibC/malloc.cpp | 14 ++++----- LibC/mman.cpp | 7 ++--- LibC/mntent.cpp | 4 +-- LibC/poll.cpp | 4 +-- LibC/pwd.cpp | 5 ++-- LibC/qsort.cpp | 52 +++++++++++++++++---------------- LibC/scanf.cpp | 25 ++++++++-------- LibC/sched.cpp | 10 +++---- LibC/sched.h | 6 ++-- LibC/signal.cpp | 9 +++--- LibC/stat.cpp | 10 +++---- LibC/stdio.cpp | 3 -- LibC/stdlib.cpp | 17 +++++------ LibC/string.cpp | 67 +++++++++++++++++++------------------------ LibC/strings.cpp | 3 +- LibC/sys/cdefs.h | 2 +- LibC/sys/select.cpp | 3 +- LibC/sys/socket.cpp | 7 ++--- LibC/sys/uio.cpp | 5 ++-- LibC/sys/wait.cpp | 3 +- LibC/termcap.cpp | 12 ++++---- LibC/termios.cpp | 10 +++---- LibC/time.cpp | 11 ++++--- LibC/times.cpp | 4 +-- LibC/ulimit.cpp | 7 ++--- LibC/unistd.cpp | 29 +++++++++---------- LibC/utime.cpp | 6 ++-- LibC/utsname.cpp | 6 ++-- 40 files changed, 181 insertions(+), 234 deletions(-) diff --git a/LibC/SharedBuffer.cpp b/LibC/SharedBuffer.cpp index ef8c262075..58537a0094 100644 --- a/LibC/SharedBuffer.cpp +++ b/LibC/SharedBuffer.cpp @@ -1,7 +1,7 @@ -#include -#include -#include #include +#include +#include +#include RetainPtr SharedBuffer::create(pid_t peer, int size) { diff --git a/LibC/arpa/inet.cpp b/LibC/arpa/inet.cpp index 54fa4d62eb..4156a0a740 100644 --- a/LibC/arpa/inet.cpp +++ b/LibC/arpa/inet.cpp @@ -1,7 +1,7 @@ #include +#include #include #include -#include extern "C" { @@ -56,6 +56,4 @@ in_addr_t inet_addr(const char* str) return INADDR_NONE; return tmp; } - } - diff --git a/LibC/assert.cpp b/LibC/assert.cpp index bf13d8e1e9..6bc306c2ad 100644 --- a/LibC/assert.cpp +++ b/LibC/assert.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include extern "C" { @@ -11,8 +11,8 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const dbgprintf("USERSPACE(%d) ASSERTION FAILED: %s\n%s:%u in %s\n", getpid(), msg, file, line, func); fprintf(stderr, "ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func); abort(); - for (;;); + for (;;) + ; } #endif - } diff --git a/LibC/crt0.cpp b/LibC/crt0.cpp index ee307daa81..82005fc9a2 100644 --- a/LibC/crt0.cpp +++ b/LibC/crt0.cpp @@ -51,5 +51,4 @@ int _start(int argc, char** argv, char** env) void __cxa_atexit() { } - } diff --git a/LibC/ctype.cpp b/LibC/ctype.cpp index 9d4c426ba7..beb0008e8d 100644 --- a/LibC/ctype.cpp +++ b/LibC/ctype.cpp @@ -5,18 +5,18 @@ extern "C" { const char _ctype_[256] = { _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, + _C, _C | _S, _C | _S, _C | _S, _C | _S, _C | _S, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, - (char)(_S|_B), _P, _P, _P, _P, _P, _P, _P, + (char)(_S | _B), _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _N, _N, _N, _N, _N, _N, _N, _N, _N, _N, _P, _P, _P, _P, _P, _P, - _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, + _P, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _P, _P, _P, _P, _P, - _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, + _P, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _P, _P, _P, _P, _C @@ -35,5 +35,4 @@ int toupper(int c) return c & ~0x20; return c; } - } diff --git a/LibC/dirent.cpp b/LibC/dirent.cpp index cf2e8b5498..07a9ef22ff 100644 --- a/LibC/dirent.cpp +++ b/LibC/dirent.cpp @@ -9,7 +9,6 @@ #include #include #include -#include extern "C" { @@ -39,7 +38,8 @@ int closedir(DIR* dirp) return rc; } -struct [[gnu::packed]] sys_dirent { +struct [[gnu::packed]] sys_dirent +{ ino_t ino; byte file_type; size_t namelen; @@ -91,6 +91,4 @@ int dirfd(DIR* dirp) ASSERT(dirp); return dirp->fd; } - } - diff --git a/LibC/dlfcn.cpp b/LibC/dlfcn.cpp index 08c5e12490..f4437b0272 100644 --- a/LibC/dlfcn.cpp +++ b/LibC/dlfcn.cpp @@ -8,19 +8,18 @@ int dlclose(void*) ASSERT_NOT_REACHED(); } -char *dlerror() +char* dlerror() { ASSERT_NOT_REACHED(); } -void *dlopen(const char*, int) +void* dlopen(const char*, int) { ASSERT_NOT_REACHED(); } -void *dlsym(void*, const char*) +void* dlsym(void*, const char*) { ASSERT_NOT_REACHED(); } - } diff --git a/LibC/fcntl.cpp b/LibC/fcntl.cpp index dd28a65cb6..ba4e425e1c 100644 --- a/LibC/fcntl.cpp +++ b/LibC/fcntl.cpp @@ -1,8 +1,8 @@ +#include #include #include #include #include -#include extern "C" { @@ -14,5 +14,4 @@ int fcntl(int fd, int cmd, ...) int rc = syscall(SC_fcntl, fd, cmd, extra_arg); __RETURN_WITH_ERRNO(rc, rc, -1); } - } diff --git a/LibC/getopt.cpp b/LibC/getopt.cpp index c7c6afa637..6798b65cbe 100644 --- a/LibC/getopt.cpp +++ b/LibC/getopt.cpp @@ -40,20 +40,20 @@ #include #include -int opterr = 1; /* if error message should be printed */ +int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt; /* character checked for validity */ int optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ +char* optarg; /* argument associated with option */ -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" int getopt(int nargc, char* const nargv[], const char* ostr) { static const char* place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ + char* oli; /* option letter list index */ ASSERT(nargv != NULL); ASSERT(ostr != NULL); @@ -70,7 +70,7 @@ int getopt(int nargc, char* const nargv[], const char* ostr) place = EMSG; return -1; } - } /* option letter okay? */ + } /* option letter okay? */ if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr, optopt))) { /* * if the user didn't specify '-' as an option, @@ -88,8 +88,7 @@ int getopt(int nargc, char* const nargv[], const char* ostr) optarg = NULL; if (!*place) ++optind; - } - else { /* need an argument */ + } else { /* need an argument */ if (*place) /* no white space */ optarg = const_cast(place); else if (nargc <= ++optind) { /* no arg */ @@ -99,8 +98,7 @@ int getopt(int nargc, char* const nargv[], const char* ostr) if (opterr) fprintf(stderr, "option requires an argument -- %c\n", optopt); return BADCH; - } - else /* white space */ + } else /* white space */ optarg = nargv[optind]; place = EMSG; ++optind; diff --git a/LibC/grp.cpp b/LibC/grp.cpp index 744189bb80..2379d98e35 100644 --- a/LibC/grp.cpp +++ b/LibC/grp.cpp @@ -1,9 +1,9 @@ +#include #include #include #include -#include #include -#include +#include extern "C" { @@ -138,5 +138,4 @@ int initgroups(const char* user, gid_t extra_gid) gids[count++] = extra_gid; return setgroups(count, gids); } - } diff --git a/LibC/ioctl.cpp b/LibC/ioctl.cpp index 354d49e7b7..c2ac90524a 100644 --- a/LibC/ioctl.cpp +++ b/LibC/ioctl.cpp @@ -1,8 +1,8 @@ +#include #include #include #include #include -#include extern "C" { @@ -14,6 +14,4 @@ int ioctl(int fd, unsigned request, ...) int rc = syscall(SC_ioctl, fd, request, arg); __RETURN_WITH_ERRNO(rc, rc, -1); } - } - diff --git a/LibC/locale.cpp b/LibC/locale.cpp index 62bd414b7c..a85af30784 100644 --- a/LibC/locale.cpp +++ b/LibC/locale.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include extern "C" { @@ -20,5 +20,4 @@ struct lconv* localeconv() { return &default_locale; } - } diff --git a/LibC/malloc.cpp b/LibC/malloc.cpp index 21021ba03d..2225ba9caa 100644 --- a/LibC/malloc.cpp +++ b/LibC/malloc.cpp @@ -1,11 +1,11 @@ #include #include #include -#include -#include #include -#include #include +#include +#include +#include // FIXME: Thread safety. @@ -16,7 +16,7 @@ #define FREE_SCRUB_BYTE 0x82 #define MAGIC_PAGE_HEADER 0x42657274 #define MAGIC_BIGALLOC_HEADER 0x42697267 -#define PAGE_ROUND_UP(x) ((((size_t)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1))) +#define PAGE_ROUND_UP(x) ((((size_t)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1))) static const size_t number_of_chunked_blocks_to_keep_around_per_size_class = 32; static const size_t number_of_big_blocks_to_keep_around_per_size_class = 8; @@ -45,7 +45,8 @@ struct FreelistEntry { FreelistEntry* next; }; -struct ChunkedBlock : public CommonHeader, public InlineLinkedListNode { +struct ChunkedBlock : public CommonHeader + , public InlineLinkedListNode { ChunkedBlock(size_t bytes_per_chunk) { m_magic = MAGIC_PAGE_HEADER; @@ -59,7 +60,6 @@ struct ChunkedBlock : public CommonHeader, public InlineLinkedListNodenext = nullptr; } - } ChunkedBlock* m_prev { nullptr }; @@ -309,6 +309,4 @@ void __malloc_init() if (getenv("LIBC_LOG_MALLOC")) s_log_malloc = true; } - } - diff --git a/LibC/mman.cpp b/LibC/mman.cpp index bd87e5989c..0e89a4ead0 100644 --- a/LibC/mman.cpp +++ b/LibC/mman.cpp @@ -1,7 +1,7 @@ -#include -#include -#include #include +#include +#include +#include extern "C" { @@ -50,5 +50,4 @@ int shm_unlink(const char* name) int rc = syscall(SC_unlink, name); __RETURN_WITH_ERRNO(rc, rc, -1); } - } diff --git a/LibC/mntent.cpp b/LibC/mntent.cpp index 08116ec02b..3cc16cc8bf 100644 --- a/LibC/mntent.cpp +++ b/LibC/mntent.cpp @@ -1,5 +1,5 @@ -#include #include +#include extern "C" { @@ -8,6 +8,4 @@ struct mntent* getmntent(FILE*) ASSERT_NOT_REACHED(); return nullptr; } - } - diff --git a/LibC/poll.cpp b/LibC/poll.cpp index 2e3f939a80..9394048801 100644 --- a/LibC/poll.cpp +++ b/LibC/poll.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include extern "C" { @@ -9,6 +9,4 @@ int poll(struct pollfd* fds, int nfds, int timeout) int rc = syscall(SC_poll, fds, nfds, timeout); __RETURN_WITH_ERRNO(rc, rc, -1); } - } - diff --git a/LibC/pwd.cpp b/LibC/pwd.cpp index 9bed1d1bd0..3303cf3d91 100644 --- a/LibC/pwd.cpp +++ b/LibC/pwd.cpp @@ -1,9 +1,9 @@ +#include #include #include #include -#include #include -#include +#include extern "C" { @@ -125,5 +125,4 @@ next_entry: strncpy(__pwdb_entry->shell_buffer, e_shell.characters(), PWDB_STR_MAX_LEN); return __pwdb_entry; } - } diff --git a/LibC/qsort.cpp b/LibC/qsort.cpp index 3bf55bc639..8946da07c2 100644 --- a/LibC/qsort.cpp +++ b/LibC/qsort.cpp @@ -35,16 +35,16 @@ static char sccsid[] = "@(#)qsort.c 5.9 (Berkeley) 2/23/91"; #endif /* LIBC_SCCS and not lint */ -#include #include +#include static void insertion_sort(void* bot, size_t nmemb, size_t size, int (*compar)(const void*, const void*)); static void insertion_sort_r(void* bot, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void* arg); -void qsort(void* bot, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) +void qsort(void* bot, size_t nmemb, size_t size, int (*compar)(const void*, const void*)) { - if (nmemb <= 1) - return; + if (nmemb <= 1) + return; insertion_sort(bot, nmemb, size, compar); } @@ -64,27 +64,29 @@ void insertion_sort(void* bot, size_t nmemb, size_t size, int (*compar)(const vo char *s1, *s2, *t1, *t2, *top; top = (char*)bot + nmemb * size; for (t1 = (char*)bot + size; t1 < top;) { - for (t2 = t1; (t2 -= size) >= bot && compar(t1, t2) < 0;); - if (t1 != (t2 += size)) { - for (cnt = size; cnt--; ++t1) { - ch = *t1; - for (s1 = s2 = t1; (s2 -= size) >= t2; s1 = s2) - *s1 = *s2; - *s1 = ch; - } - } else - t1 += size; - } -} - -void insertion_sort_r(void* bot, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void* arg) -{ - int cnt; - unsigned char ch; - char *s1, *s2, *t1, *t2, *top; - top = (char*)bot + nmemb * size; - for (t1 = (char*)bot + size; t1 < top;) { - for (t2 = t1; (t2 -= size) >= bot && compar(t1, t2, arg) < 0;); + for (t2 = t1; (t2 -= size) >= bot && compar(t1, t2) < 0;) + ; + if (t1 != (t2 += size)) { + for (cnt = size; cnt--; ++t1) { + ch = *t1; + for (s1 = s2 = t1; (s2 -= size) >= t2; s1 = s2) + *s1 = *s2; + *s1 = ch; + } + } else + t1 += size; + } +} + +void insertion_sort_r(void* bot, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void* arg) +{ + int cnt; + unsigned char ch; + char *s1, *s2, *t1, *t2, *top; + top = (char*)bot + nmemb * size; + for (t1 = (char*)bot + size; t1 < top;) { + for (t2 = t1; (t2 -= size) >= bot && compar(t1, t2, arg) < 0;) + ; if (t1 != (t2 += size)) { for (cnt = size; cnt--; ++t1) { ch = *t1; diff --git a/LibC/scanf.cpp b/LibC/scanf.cpp index 4aaa818177..bbf86cd1b5 100644 --- a/LibC/scanf.cpp +++ b/LibC/scanf.cpp @@ -28,10 +28,10 @@ * SUCH DAMAGE. * */ -#include -#include -#include #include +#include +#include +#include static const char* determine_base(const char* p, int& base) { @@ -119,31 +119,32 @@ int atob(unsigned int* vp, const char* p, int base) #define ISSPACE " \t\n\r\f\v" -int vsscanf(const char *buf, const char *s, va_list ap) +int vsscanf(const char* buf, const char* s, va_list ap) { int base = 10; - char *t; + char* t; char tmp[BUFSIZ]; bool noassign = false; int count = 0; int width = 0; while (*s && *buf) { - while (isspace (*s)) + while (isspace(*s)) s++; if (*s == '%') { s++; for (; *s; s++) { - if (strchr ("dibouxcsefg%", *s)) + if (strchr("dibouxcsefg%", *s)) break; if (*s == '*') noassign = true; else if (*s >= '1' && *s <= '9') { const char* tc; - for (tc = s; isdigit(*s); s++); - strncpy (tmp, tc, s - tc); + for (tc = s; isdigit(*s); s++) + ; + strncpy(tmp, tc, s - tc); tmp[s - tc] = '\0'; - atob ((uint32_t*)&width, tmp, 10); + atob((uint32_t*)&width, tmp, 10); s--; } } @@ -180,7 +181,7 @@ int vsscanf(const char *buf, const char *s, va_list ap) if (isspace(*(s + 1)) || *(s + 1) == 0) { width = strcspn(buf, ISSPACE); } else { - auto* p = strchr(buf, *(s+1)); + auto* p = strchr(buf, *(s + 1)); if (p) width = p - buf; else { @@ -204,7 +205,7 @@ int vsscanf(const char *buf, const char *s, va_list ap) ++s; } else { while (isspace(*buf)) - buf++; + buf++; if (*s != *buf) break; else { diff --git a/LibC/sched.cpp b/LibC/sched.cpp index b083595cc9..7c88f7c5d0 100644 --- a/LibC/sched.cpp +++ b/LibC/sched.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include extern "C" { @@ -22,17 +22,15 @@ int sched_get_priority_max(int policy) return 3; // High } -int sched_setparam(pid_t pid, const struct sched_param *param) +int sched_setparam(pid_t pid, const struct sched_param* param) { int rc = syscall(SC_sched_setparam, pid, param); __RETURN_WITH_ERRNO(rc, rc, -1); } -int sched_getparam(pid_t pid, struct sched_param *param) +int sched_getparam(pid_t pid, struct sched_param* param) { int rc = syscall(SC_sched_getparam, pid, param); __RETURN_WITH_ERRNO(rc, rc, -1); } - } - diff --git a/LibC/sched.h b/LibC/sched.h index d1be1fdda0..080bfc070a 100644 --- a/LibC/sched.h +++ b/LibC/sched.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include __BEGIN_DECLS @@ -18,7 +18,7 @@ struct sched_param { int sched_get_priority_min(int policy); int sched_get_priority_max(int policy); -int sched_setparam(pid_t pid, const struct sched_param *param); -int sched_getparam(pid_t pid, struct sched_param *param); +int sched_setparam(pid_t pid, const struct sched_param* param); +int sched_getparam(pid_t pid, struct sched_param* param); __END_DECLS diff --git a/LibC/signal.cpp b/LibC/signal.cpp index 79f1bd5eb6..59ad5fa1f6 100644 --- a/LibC/signal.cpp +++ b/LibC/signal.cpp @@ -1,10 +1,10 @@ -#include +#include +#include #include +#include #include #include -#include -#include -#include +#include extern "C" { @@ -160,5 +160,4 @@ int sigsuspend(const sigset_t*) dbgprintf("FIXME: Implement sigsuspend()\n"); ASSERT_NOT_REACHED(); } - } diff --git a/LibC/stat.cpp b/LibC/stat.cpp index 8c1f84458f..e74ef33a3f 100644 --- a/LibC/stat.cpp +++ b/LibC/stat.cpp @@ -1,8 +1,8 @@ -#include -#include -#include -#include #include +#include +#include +#include +#include extern "C" { @@ -28,6 +28,4 @@ int fchmod(int fd, mode_t mode) int rc = syscall(SC_fchmod, fd, mode); __RETURN_WITH_ERRNO(rc, rc, -1); } - } - diff --git a/LibC/stdio.cpp b/LibC/stdio.cpp index 926f67f8f3..7394819c94 100644 --- a/LibC/stdio.cpp +++ b/LibC/stdio.cpp @@ -11,7 +11,6 @@ #include #include #include -#include extern "C" { @@ -573,6 +572,4 @@ FILE* tmpfile() dbgprintf("FIXME: Implement tmpfile()\n"); ASSERT_NOT_REACHED(); } - } - diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index 3f4b64329c..d9a6c70fc3 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -18,7 +18,7 @@ extern "C" { -typedef void(*__atexit_handler)(); +typedef void (*__atexit_handler)(); static int __atexit_handler_count = 0; static __atexit_handler __atexit_handlers[32]; @@ -41,7 +41,6 @@ int atexit(void (*handler)()) return 0; } - void abort() { raise(SIGABRT); @@ -98,8 +97,8 @@ int unsetenv(const char* name) return 0; // not found: no failure. // Shuffle the existing array down by one. - memmove(&environ[skip], &environ[skip+1], ((environ_size-1)-skip) * sizeof(environ[0])); - environ[environ_size-1] = nullptr; + memmove(&environ[skip], &environ[skip + 1], ((environ_size - 1) - skip) * sizeof(environ[0])); + environ[environ_size - 1] = nullptr; free_environment_variable_if_needed(name); return 0; @@ -143,7 +142,7 @@ int putenv(char* new_var) // At this point, we need to append the new var. // 2 here: one for the new var, one for the sentinel value. - char **new_environ = (char**)malloc((environ_size + 2) * sizeof(char*)); + char** new_environ = (char**)malloc((environ_size + 2) * sizeof(char*)); if (new_environ == nullptr) { errno = ENOMEM; return -1; @@ -237,7 +236,7 @@ static unsigned long s_next_rand = 1; int rand() { s_next_rand = s_next_rand * 1103515245 + 12345; - return((unsigned)(s_next_rand/((RAND_MAX + 1) * 2)) % (RAND_MAX + 1)); + return ((unsigned)(s_next_rand / ((RAND_MAX + 1) * 2)) % (RAND_MAX + 1)); } void srand(unsigned seed) @@ -302,7 +301,7 @@ char* mktemp(char* pattern) return pattern; } -void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) +void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*)) { dbgprintf("FIXME(LibC): bsearch(%p, %p, %u, %u, %p)\n", key, base, nmemb, size, compar); ASSERT_NOT_REACHED(); @@ -347,8 +346,7 @@ long strtol(const char* str, char** endptr, int base) c = *s++; } else if (c == '+') c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; @@ -392,5 +390,4 @@ unsigned long strtoul(const char* str, char** endptr, int base) ASSERT(value >= 0); return value; } - } diff --git a/LibC/string.cpp b/LibC/string.cpp index 1f36864a77..dcd795fd30 100644 --- a/LibC/string.cpp +++ b/LibC/string.cpp @@ -1,12 +1,12 @@ -#include -#include -#include -#include -#include -#include -#include -#include #include "ctype.h" +#include +#include +#include +#include +#include +#include +#include +#include extern "C" { @@ -42,7 +42,7 @@ size_t strcspn(const char* s, const char* reject) do { if ((rc = *rp++) == c) return p - 1 - s; - } while(rc); + } while (rc); } } @@ -146,17 +146,14 @@ void* memcpy(void* dest_ptr, const void* src_ptr, size_t n) "rep movsl\n" : "=S"(src), "=D"(dest) : "S"(src), "D"(dest), "c"(dwords) - : "memory" - ); + : "memory"); n -= dwords * sizeof(dword); if (n == 0) return dest_ptr; } asm volatile( - "rep movsb\n" - :: "S"(src), "D"(dest), "c"(n) - : "memory" - ); + "rep movsb\n" ::"S"(src), "D"(dest), "c"(n) + : "memory"); return dest_ptr; } @@ -173,38 +170,36 @@ void* memset(void* dest_ptr, int c, size_t n) "rep stosl\n" : "=D"(dest) : "D"(dest), "c"(dwords), "a"(expanded_c) - : "memory" - ); + : "memory"); n -= dwords * sizeof(dword); if (n == 0) return dest_ptr; } asm volatile( "rep stosb\n" - : "=D" (dest), "=c" (n) - : "0" (dest), "1" (n), "a" (c) - : "memory" - ); + : "=D"(dest), "=c"(n) + : "0"(dest), "1"(n), "a"(c) + : "memory"); return dest_ptr; } - void* memmove(void* dest, const void* src, size_t n) { if (dest < src) return memcpy(dest, src, n); - byte *pd = (byte*)dest; - const byte *ps = (const byte*)src; + byte* pd = (byte*)dest; + const byte* ps = (const byte*)src; for (pd += n, ps += n; n--;) *--pd = *--ps; return dest; } -char* strcpy(char* dest, const char *src) +char* strcpy(char* dest, const char* src) { char* originalDest = dest; - while ((*dest++ = *src++) != '\0'); + while ((*dest++ = *src++) != '\0') + ; return originalDest; } @@ -213,7 +208,7 @@ char* strncpy(char* dest, const char* src, size_t n) size_t i; for (i = 0; i < n && src[i] != '\0'; ++i) dest[i] = src[i]; - for ( ; i < n; ++i) + for (; i < n; ++i) dest[i] = '\0'; return dest; } @@ -242,7 +237,7 @@ void* memchr(const void* ptr, int c, size_t size) char* strrchr(const char* str, int ch) { - char *last = nullptr; + char* last = nullptr; char c; for (; (c = *str); ++str) { if (c == ch) @@ -251,21 +246,21 @@ char* strrchr(const char* str, int ch) return last; } -char* strcat(char *dest, const char *src) +char* strcat(char* dest, const char* src) { size_t dest_length = strlen(dest); size_t i; - for (i = 0 ; src[i] != '\0' ; i++) + for (i = 0; src[i] != '\0'; i++) dest[dest_length + i] = src[i]; dest[dest_length + i] = '\0'; return dest; } -char* strncat(char *dest, const char *src, size_t n) +char* strncat(char* dest, const char* src, size_t n) { size_t dest_length = strlen(dest); size_t i; - for (i = 0 ; i < n && src[i] != '\0' ; i++) + for (i = 0; i < n && src[i] != '\0'; i++) dest[dest_length + i] = src[i]; dest[dest_length + i] = '\0'; return dest; @@ -387,12 +382,12 @@ char* strstr(const char* haystack, const char* needle) char* strpbrk(const char* s, const char* accept) { while (*s) - if(strchr(accept, *s++)) + if (strchr(accept, *s++)) return const_cast(--s); return nullptr; } -char *strtok(char* str, const char* delim) +char* strtok(char* str, const char* delim) { (void)str; (void)delim; @@ -409,10 +404,8 @@ size_t strxfrm(char* dest, const char* src, size_t n) size_t i; for (i = 0; i < n && src[i] != '\0'; ++i) dest[i] = src[i]; - for ( ; i < n; ++i) + for (; i < n; ++i) dest[i] = '\0'; return i; } - } - diff --git a/LibC/strings.cpp b/LibC/strings.cpp index abbfeca214..8f248e1438 100644 --- a/LibC/strings.cpp +++ b/LibC/strings.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include extern "C" { @@ -32,5 +32,4 @@ int strncasecmp(const char* s1, const char* s2, size_t n) } while (--n); return 0; } - } diff --git a/LibC/sys/cdefs.h b/LibC/sys/cdefs.h index 1b6b52cca2..f83fbad3c2 100644 --- a/LibC/sys/cdefs.h +++ b/LibC/sys/cdefs.h @@ -3,7 +3,7 @@ #define _POSIX_VERSION 200809L #ifndef ALWAYS_INLINE -#define ALWAYS_INLINE inline __attribute__((always_inline)) +# define ALWAYS_INLINE inline __attribute__((always_inline)) #endif #ifdef __cplusplus diff --git a/LibC/sys/select.cpp b/LibC/sys/select.cpp index 70a46e7850..60d54a20c8 100644 --- a/LibC/sys/select.cpp +++ b/LibC/sys/select.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include extern "C" { @@ -11,5 +11,4 @@ int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, struc int rc = syscall(SC_select, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } - } diff --git a/LibC/sys/socket.cpp b/LibC/sys/socket.cpp index 3206832a96..85f2b09ab9 100644 --- a/LibC/sys/socket.cpp +++ b/LibC/sys/socket.cpp @@ -1,8 +1,8 @@ -#include -#include -#include #include +#include +#include #include +#include extern "C" { @@ -85,5 +85,4 @@ int getpeername(int sockfd, struct sockaddr* addr, socklen_t* addrlen) int rc = syscall(SC_getpeername, sockfd, addr, addrlen); __RETURN_WITH_ERRNO(rc, rc, -1); } - } diff --git a/LibC/sys/uio.cpp b/LibC/sys/uio.cpp index efa4a1b5eb..f57f29bb7a 100644 --- a/LibC/sys/uio.cpp +++ b/LibC/sys/uio.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include extern "C" { @@ -9,5 +9,4 @@ ssize_t writev(int fd, const struct iovec* iov, int iov_count) int rc = syscall(SC_writev, fd, iov, iov_count); __RETURN_WITH_ERRNO(rc, rc, -1); } - } diff --git a/LibC/sys/wait.cpp b/LibC/sys/wait.cpp index d010b39cba..9b0762653c 100644 --- a/LibC/sys/wait.cpp +++ b/LibC/sys/wait.cpp @@ -1,6 +1,6 @@ +#include #include #include -#include extern "C" { @@ -8,5 +8,4 @@ pid_t wait(int* wstatus) { return waitpid(-1, wstatus, 0); } - } diff --git a/LibC/termcap.cpp b/LibC/termcap.cpp index 9d34bc18f1..98b55a2e54 100644 --- a/LibC/termcap.cpp +++ b/LibC/termcap.cpp @@ -1,9 +1,9 @@ -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include //#define TERMCAP_DEBUG @@ -126,6 +126,4 @@ int tputs(const char* str, int affcnt, int (*putc)(int)) putc(str[i]); return 0; } - } - diff --git a/LibC/termios.cpp b/LibC/termios.cpp index 0e44aad819..be70fc6685 100644 --- a/LibC/termios.cpp +++ b/LibC/termios.cpp @@ -1,8 +1,8 @@ +#include #include #include -#include #include -#include +#include extern "C" { @@ -27,8 +27,8 @@ int tcsetattr(int fd, int optional_actions, const struct termios* t) int tcflow(int fd, int action) { - (void) fd; - (void) action; + (void)fd; + (void)action; ASSERT_NOT_REACHED(); } @@ -48,6 +48,4 @@ speed_t cfgetospeed(const struct termios* tp) { return tp->c_ospeed; } - } - diff --git a/LibC/time.cpp b/LibC/time.cpp index 30b6b296e6..6024664fed 100644 --- a/LibC/time.cpp +++ b/LibC/time.cpp @@ -1,9 +1,9 @@ -#include +#include +#include +#include #include #include -#include -#include -#include +#include extern "C" { @@ -91,7 +91,7 @@ struct tm* gmtime(const time_t* t) return localtime(t); } -char *asctime(const struct tm*) +char* asctime(const struct tm*) { ASSERT_NOT_REACHED(); } @@ -117,5 +117,4 @@ clock_t clock() times(&tms); return tms.tms_utime + tms.tms_stime; } - } diff --git a/LibC/times.cpp b/LibC/times.cpp index 7411af706d..76301ec0e0 100644 --- a/LibC/times.cpp +++ b/LibC/times.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include clock_t times(struct tms* buf) { diff --git a/LibC/ulimit.cpp b/LibC/ulimit.cpp index c16a06fe1a..14e7cb8c34 100644 --- a/LibC/ulimit.cpp +++ b/LibC/ulimit.cpp @@ -1,13 +1,12 @@ -#include #include +#include extern "C" { long ulimit(int cmd, long newlimit) { - (void) cmd; - (void) newlimit; + (void)cmd; + (void)newlimit; ASSERT_NOT_REACHED(); } - } diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp index 6c02793aa1..473c2b605d 100644 --- a/LibC/unistd.cpp +++ b/LibC/unistd.cpp @@ -1,18 +1,18 @@ -#include -#include -#include -#include +#include +#include +#include #include +#include +#include #include #include +#include #include #include +#include #include #include -#include -#include -#include -#include +#include extern "C" { @@ -225,7 +225,7 @@ int stat(const char* path, struct stat* statbuf) __RETURN_WITH_ERRNO(rc, rc, -1); } -int fstat(int fd, struct stat *statbuf) +int fstat(int fd, struct stat* statbuf) { int rc = syscall(SC_fstat, fd, statbuf); __RETURN_WITH_ERRNO(rc, rc, -1); @@ -378,15 +378,15 @@ int mknod(const char* pathname, mode_t mode, dev_t dev) long fpathconf(int fd, int name) { - (void) fd; - (void) name; + (void)fd; + (void)name; ASSERT_NOT_REACHED(); } long pathconf(const char* path, int name) { - (void) path; - (void) name; + (void)path; + (void)name; ASSERT_NOT_REACHED(); } @@ -451,7 +451,7 @@ char* getlogin() return nullptr; } -int create_thread(int(*entry)(void*), void* argument) +int create_thread(int (*entry)(void*), void* argument) { int rc = syscall(SC_create_thread, entry, argument); __RETURN_WITH_ERRNO(rc, rc, -1); @@ -492,5 +492,4 @@ int fsync(int fd) dbgprintf("FIXME: Implement fsync()\n"); return 0; } - } diff --git a/LibC/utime.cpp b/LibC/utime.cpp index 737d958e49..e8517ab4df 100644 --- a/LibC/utime.cpp +++ b/LibC/utime.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include extern "C" { @@ -9,6 +9,4 @@ int utime(const char* pathname, const struct utimbuf* buf) int rc = syscall(SC_utime, (dword)pathname, (dword)buf); __RETURN_WITH_ERRNO(rc, rc, -1); } - } - diff --git a/LibC/utsname.cpp b/LibC/utsname.cpp index bc8d5f02a6..7b03cc1ae7 100644 --- a/LibC/utsname.cpp +++ b/LibC/utsname.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include extern "C" { @@ -9,6 +9,4 @@ int uname(struct utsname* buf) int rc = syscall(SC_uname, buf); __RETURN_WITH_ERRNO(rc, rc, -1); } - } -