Get rid of writefmt functions
This commit is contained in:
@ -14,7 +14,6 @@ SRCFILES := $(call GRABSRC, \
|
||||
args \
|
||||
util \
|
||||
ubsan \
|
||||
write \
|
||||
umalloc \
|
||||
)
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
#ifndef ULIB_ASSERT_H_
|
||||
#define ULIB_ASSERT_H_
|
||||
|
||||
#include <write/write.h>
|
||||
#include <util/util.h>
|
||||
#include <uprintf.h>
|
||||
|
||||
#define ASSERT(X, fmt, ...) \
|
||||
do { \
|
||||
if (!(X)) { \
|
||||
writefmt("ASSERT {s}:{d} in {s} "fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
|
||||
uprintf("ASSERT %s:%d in %s "fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
|
||||
quit(); \
|
||||
} \
|
||||
} while(0)
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define ULIB_LOG_H_
|
||||
|
||||
#include <uprintf.h>
|
||||
#include <write/write.h>
|
||||
|
||||
enum {
|
||||
LOG_ERR,
|
||||
@ -13,6 +12,6 @@ enum {
|
||||
|
||||
static const char *_LOG_STR[] = { "ERROR", "DEBUG", "INFO", "WARNING" };
|
||||
|
||||
#define LOG(mode, fmt, ...) writefmt("{s}: "fmt, _LOG_STR[(mode)], ##__VA_ARGS__);
|
||||
#define LOG(mode, fmt, ...) uprintf("%s: "fmt, _LOG_STR[(mode)], ##__VA_ARGS__);
|
||||
|
||||
#endif // ULIB_LOG_H_
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <stddef.h>
|
||||
#include <string/string.h>
|
||||
#include <umalloc/umalloc.h>
|
||||
#include <write/write.h>
|
||||
|
||||
size_t string_len(const char *s) {
|
||||
size_t l = 0;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <write/write.h>
|
||||
#include <uprintf.h>
|
||||
|
||||
struct source_location {
|
||||
const char *file;
|
||||
@ -96,7 +96,7 @@ struct pointer_overflow_data {
|
||||
|
||||
static void ubsan_print(struct source_location *loc, const char *message)
|
||||
{
|
||||
writefmt("UBSAN error {s}:{d}:{d} {s}\n", loc->file, loc->line, loc->column, message);
|
||||
uprintf("UBSAN error %s:%d:%d %s\n", loc->file, loc->line, loc->column, message);
|
||||
}
|
||||
|
||||
void __ubsan_handle_add_overflow(struct overflow_data *data)
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <linklist.h>
|
||||
#include <log.h>
|
||||
#include <assert.h>
|
||||
#include <write/write.h>
|
||||
#include <umalloc/umalloc.h>
|
||||
|
||||
#include <errors.h>
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <errors.h>
|
||||
#include <linklist.h>
|
||||
#include <string/string.h>
|
||||
#include <write/write.h>
|
||||
#include <util/util.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -1,167 +0,0 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <limits.h>
|
||||
#include <system/system.h>
|
||||
#include <sysdefs/devctl.h>
|
||||
#include <write/write.h>
|
||||
#include <umalloc/umalloc.h>
|
||||
#include <string/string.h>
|
||||
#include <util/util.h>
|
||||
|
||||
char *utoa(uintmax_t v, int base, bool uppercase) {
|
||||
if (base < 2 || base > 36) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char buf[sizeof(uintmax_t) * CHAR_BIT + 3];
|
||||
const char *digits = uppercase ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
size_t i = sizeof(buf) - 1;
|
||||
buf[i] = '\0';
|
||||
|
||||
if (v == 0) {
|
||||
buf[--i] = '0';
|
||||
return &buf[i];
|
||||
}
|
||||
|
||||
while (v != 0) {
|
||||
if (i == 0) {
|
||||
return NULL;
|
||||
}
|
||||
buf[--i] = digits[v % base];
|
||||
v /= base;
|
||||
}
|
||||
|
||||
return &buf[i];
|
||||
}
|
||||
|
||||
char *itoa(intmax_t v, int base, bool uppercase) {
|
||||
if (base < 2 || base > 36) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char buf[sizeof(uintmax_t) * CHAR_BIT + 3];
|
||||
const char *digits = uppercase ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
size_t i = sizeof(buf) - 1;
|
||||
buf[i] = '\0';
|
||||
|
||||
if (v == 0) {
|
||||
buf[--i] = '0';
|
||||
return &buf[i];
|
||||
}
|
||||
|
||||
bool neg = (v < 0);
|
||||
uintmax_t u;
|
||||
if (neg) {
|
||||
u = (uintmax_t)(-(v + 1)) + 1;
|
||||
} else {
|
||||
u = (uintmax_t)v;
|
||||
}
|
||||
|
||||
while (u != 0) {
|
||||
if (i == 0) {
|
||||
return NULL;
|
||||
}
|
||||
buf[--i] = digits[u % base];
|
||||
u /= base;
|
||||
}
|
||||
|
||||
if (neg) {
|
||||
if (i == 0) {
|
||||
return NULL;
|
||||
}
|
||||
buf[--i] = '-';
|
||||
}
|
||||
|
||||
return &buf[i];
|
||||
}
|
||||
|
||||
#define FMTBUF_MAX (1024 * 4)
|
||||
|
||||
extern Dev_t termdev;
|
||||
|
||||
enum {
|
||||
WRITE_FORMATMODE,
|
||||
WRITE_NORMALMODE,
|
||||
};
|
||||
|
||||
const char *convstr1 = "0123456789abcdef";
|
||||
const char *convstr2 = "0123456789ABCDEF";
|
||||
|
||||
size_t writefmt(char *fmt, ...) {
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
size_t count = writevfmt(fmt, list);
|
||||
va_end(list);
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t writevsfmt(char *buf, char *fmt, va_list list) {
|
||||
size_t c = 0;
|
||||
int WRITE_STATE = WRITE_NORMALMODE;
|
||||
|
||||
for (size_t i = 0; fmt[i] != '\0'; i++) {
|
||||
if (WRITE_STATE == WRITE_NORMALMODE) {
|
||||
switch (fmt[i]) {
|
||||
case '{':
|
||||
WRITE_STATE = WRITE_FORMATMODE;
|
||||
break;
|
||||
default:
|
||||
buf[c++] = fmt[i];
|
||||
break;
|
||||
}
|
||||
} else if (WRITE_STATE == WRITE_FORMATMODE) {
|
||||
switch (fmt[i]) {
|
||||
case '}':
|
||||
WRITE_STATE = WRITE_NORMALMODE;
|
||||
break;
|
||||
case 's': {
|
||||
char *string = va_arg(list, char *);
|
||||
while (string && *string) { buf[c++] = *string; string++; }
|
||||
} break;
|
||||
case 'd': {
|
||||
int int1 = va_arg(list, int);
|
||||
char *string = itoa(int1, 10, false);
|
||||
while (string && *string) { buf[c++] = *string; string++; }
|
||||
} break;
|
||||
case 'x': {
|
||||
unsigned int int1 = va_arg(list, unsigned int);
|
||||
char *string = utoa(int1, 16, false);
|
||||
while (string && *string) { buf[c++] = *string; string++; }
|
||||
} break;
|
||||
case 'X': {
|
||||
unsigned int int1 = va_arg(list, unsigned int);
|
||||
char *string = utoa(int1, 16, true);
|
||||
while (string && *string) { buf[c++] = *string; string++; }
|
||||
} break;
|
||||
case 'p': {
|
||||
uintptr_t ptr = (uintptr_t)va_arg(list, void *);
|
||||
char *string = utoa(ptr, 16, false);
|
||||
while (string && *string) { buf[c++] = *string; string++; }
|
||||
} break;
|
||||
case 'P': {
|
||||
uintptr_t ptr = (uintptr_t)va_arg(list, void *);
|
||||
char *string = utoa(ptr, 16, true);
|
||||
while (string && *string) { buf[c++] = *string; string++; }
|
||||
} break;
|
||||
case 'c': {
|
||||
int c1 = va_arg(list, int);
|
||||
buf[c++] = (char)c1;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
size_t writevfmt(char *fmt, va_list list) {
|
||||
char buf[FMTBUF_MAX];
|
||||
string_memset(buf, 0, FMTBUF_MAX);
|
||||
size_t count = writevsfmt(buf, fmt, list);
|
||||
devctl(&termdev, 0x00, buf, count, 0);
|
||||
return count;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
#ifndef ULIB_WRITE_WRITE_H_
|
||||
#define ULIB_WRITE_WRITE_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
size_t writefmt(char *fmt, ...);
|
||||
size_t writevfmt(char *fmt, va_list list);
|
||||
size_t writevsfmt(char *buf, char *fmt, va_list list);
|
||||
|
||||
#endif // ULIB_WRITE_WRITE_H_
|
Reference in New Issue
Block a user