Run clang-format (#1197)

This commit is contained in:
Jōshin 2024-06-01 13:30:43 -07:00 committed by GitHub
parent ea081b262c
commit f032b5570b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
183 changed files with 1074 additions and 983 deletions

View file

@ -18,10 +18,10 @@
*/
#include "libc/calls/struct/rusage.h"
#include "libc/fmt/itoa.h"
#include "libc/serialize.h"
#include "libc/log/log.h"
#include "libc/math.h"
#include "libc/runtime/clktck.h"
#include "libc/serialize.h"
#include "libc/stdio/append.h"
struct State {

View file

@ -36,7 +36,8 @@ COSMOPOLITAN_C_START_
: "=r"(Info)); \
Cond = (x); \
++Info->total; \
if (Cond) ++Info->taken; \
if (Cond) \
++Info->taken; \
Cond; \
})

View file

@ -31,7 +31,8 @@ int AttachDebugger(intptr_t);
while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \
if (g_gdbsync) { \
g_gdbsync = 0; \
if (Rc > 0) Pid = 0; \
if (Rc > 0) \
Pid = 0; \
break; \
} else { \
sched_yield(); \

View file

@ -5,13 +5,15 @@ COSMOPOLITAN_C_START_
forceinline unsigned long __strlen(const char *s) {
unsigned long n = 0;
while (*s++) ++n;
while (*s++)
++n;
return n;
}
forceinline int __strcmp(const char *l, const char *r) {
size_t i = 0;
while (l[i] == r[i] && r[i]) ++i;
while (l[i] == r[i] && r[i])
++i;
return (l[i] & 255) - (r[i] & 255);
}
@ -86,12 +88,14 @@ forceinline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
}
forceinline char *__intcpy(char p[hasatleast 21], int64_t x) {
if (x < 0) *p++ = '-', x = -(uint64_t)x;
if (x < 0)
*p++ = '-', x = -(uint64_t)x;
return __uintcpy(p, x);
}
forceinline char *__fixcpy(char p[hasatleast 17], uint64_t x, uint8_t k) {
while (k > 0) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
while (k > 0)
*p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
*p = '\0';
return p;
}
@ -114,11 +118,15 @@ forceinline char *__strstr(const char *haystack, const char *needle) {
size_t i;
for (;;) {
for (i = 0;; ++i) {
if (!needle[i]) return (/*unconst*/ char *)haystack;
if (!haystack[i]) break;
if (needle[i] != haystack[i]) break;
if (!needle[i])
return (/*unconst*/ char *)haystack;
if (!haystack[i])
break;
if (needle[i] != haystack[i])
break;
}
if (!*haystack++) break;
if (!*haystack++)
break;
}
return 0;
}
@ -128,35 +136,44 @@ forceinline char16_t *__strstr16(const char16_t *haystack,
size_t i;
for (;;) {
for (i = 0;; ++i) {
if (!needle[i]) return (/*unconst*/ char16_t *)haystack;
if (!haystack[i]) break;
if (needle[i] != haystack[i]) break;
if (!needle[i])
return (/*unconst*/ char16_t *)haystack;
if (!haystack[i])
break;
if (needle[i] != haystack[i])
break;
}
if (!*haystack++) break;
if (!*haystack++)
break;
}
return 0;
}
forceinline const char *__strchr(const char *s, unsigned char c) {
for (;; ++s) {
if ((*s & 255) == c) return s;
if (!*s) return 0;
if ((*s & 255) == c)
return s;
if (!*s)
return 0;
}
}
forceinline unsigned long __atoul(const char *p) {
int c;
unsigned long x = 0;
while ('0' <= (c = *p++) && c <= '9') x *= 10, x += c - '0';
while ('0' <= (c = *p++) && c <= '9')
x *= 10, x += c - '0';
return x;
}
forceinline long __atol(const char *p) {
int s = *p;
unsigned long x;
if (s == '-' || s == '+') ++p;
if (s == '-' || s == '+')
++p;
x = __atoul(p);
if (s == '-') x = -x;
if (s == '-')
x = -x;
return x;
}

View file

@ -61,22 +61,26 @@ extern unsigned __log_level; /* log level for runtime check */
// log a message with the specified log level (not checking if LOGGABLE)
#define LOGF(LEVEL, FMT, ...) \
do { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} while (0)
// report an error without backtrace and debugger invocation
#define FATALF(FMT, ...) \
do { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
_log_exit(1); \
} while (0)
#define DIEF(FMT, ...) \
do { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
__builtin_unreachable(); \
} while (0)
@ -105,51 +109,62 @@ extern unsigned __log_level; /* log level for runtime check */
#define VERBOSEF(FMT, ...) \
do { \
if (LOGGABLE(kLogVerbose)) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
#define DEBUGF(FMT, ...) \
do { \
if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
#define NOISEF(FMT, ...) \
do { \
if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
#define FLOGF(F, FMT, ...) \
do { \
if (LOGGABLE(kLogInfo)) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
#define FWARNF(F, FMT, ...) \
do { \
if (LOGGABLE(kLogWarn)) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
#define FFATALF(F, FMT, ...) \
do { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
_log_exit(1); \
} while (0)
@ -157,18 +172,22 @@ extern unsigned __log_level; /* log level for runtime check */
#define FDEBUGF(F, FMT, ...) \
do { \
if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
#define FNOISEF(F, FMT, ...) \
do { \
if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
} \
} while (0)
@ -177,9 +196,11 @@ extern unsigned __log_level; /* log level for runtime check */
int e = _log_get_errno(); \
autotype(FORM) Ax = (FORM); \
if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
_log_errno(__FILE__, __LINE__, #FORM); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
_log_set_errno(e); \
} \
Ax; \
@ -190,9 +211,11 @@ extern unsigned __log_level; /* log level for runtime check */
int e = _log_get_errno(); \
autotype(FORM) Ax = (FORM); \
if (Ax == NULL && LOGGABLE(kLogWarn)) { \
if (!_LOG_TINY) _log_untrace(); \
if (!_LOG_TINY) \
_log_untrace(); \
_log_errno(__FILE__, __LINE__, #FORM); \
if (!_LOG_TINY) _log_retrace(); \
if (!_LOG_TINY) \
_log_retrace(); \
_log_set_errno(e); \
} \
Ax; \

View file

@ -16,12 +16,12 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/serialize.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/backtrace.internal.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/serialize.h"
#include "libc/sysv/errfuns.h"
#ifdef __x86_64__