diff options
author | dzwdz | 2022-08-06 00:12:51 +0200 |
---|---|---|
committer | dzwdz | 2022-08-06 00:12:51 +0200 |
commit | 03c6f3cf458c89df17b02557cd232f9cde73ed54 (patch) | |
tree | a89076307f32d9df6eec550f175accaa73d72408 /src/user/lib | |
parent | 641b857dcfe1cfca625fbd75646b743142a9069c (diff) |
make snprintf shared; dynamic resolution support
Diffstat (limited to 'src/user/lib')
-rw-r--r-- | src/user/lib/include/stdio.h | 2 | ||||
-rw-r--r-- | src/user/lib/printf.c | 27 |
2 files changed, 0 insertions, 29 deletions
diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h index 063c81f..4d9cf94 100644 --- a/src/user/lib/include/stdio.h +++ b/src/user/lib/include/stdio.h @@ -11,11 +11,9 @@ int printf(const char *restrict fmt, ...); int fprintf(FILE *restrict f, const char *restrict fmt, ...); -int snprintf(char *restrict str, size_t len, const char *restrict fmt, ...); int vprintf(const char *restrict fmt, va_list ap); int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap); -int vsnprintf(char *restrict str, size_t len, const char *restrict fmt, va_list ap); int _klogf(const char *fmt, ...); // for kernel debugging only diff --git a/src/user/lib/printf.c b/src/user/lib/printf.c index 53b1140..cb6561b 100644 --- a/src/user/lib/printf.c +++ b/src/user/lib/printf.c @@ -12,24 +12,6 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) { return __printf_internal(fmt, ap, backend_file, f); } -static void backend_buf(void *arg, const char *buf, size_t len) { - char **ptrs = arg; - size_t space = ptrs[1] - ptrs[0]; - if (len > space) len = space; - - memcpy(ptrs[0], buf, len); - ptrs[0] += len; - /* ptrs[1] is the last byte of the buffer, it must be 0. - * on overflow: - * ptrs[0] + (ptrs[1] - ptrs[0]) = ptrs[1] */ - *ptrs[0] = '\0'; -} - -int vsnprintf(char *restrict str, size_t len, const char *restrict fmt, va_list ap) { - char *ptrs[2] = {str, str + len - 1}; - return __printf_internal(fmt, ap, backend_buf, &ptrs); -} - int printf(const char *restrict fmt, ...) { int ret; @@ -49,15 +31,6 @@ int fprintf(FILE *restrict f, const char *restrict fmt, ...) { return ret; } -int snprintf(char *restrict str, size_t len, const char *restrict fmt, ...) { - int ret; - va_list argp; - va_start(argp, fmt); - ret = vsnprintf(str, len, fmt, argp); - va_end(argp); - return ret; -} - int vprintf(const char *restrict fmt, va_list ap) { return vfprintf(stdout, fmt, ap); } |