summaryrefslogtreecommitdiff
path: root/src/init/stdlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/init/stdlib.c')
-rw-r--r--src/init/stdlib.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/init/stdlib.c b/src/init/stdlib.c
index 9b7a329..cbaed61 100644
--- a/src/init/stdlib.c
+++ b/src/init/stdlib.c
@@ -18,6 +18,26 @@ int printf(const char *fmt, ...) {
return ret;
}
+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;
+}
+
+int snprintf(char *str, size_t len, const char *fmt, ...) {
+ int ret = 0;
+ char *ptrs[2] = {str, str + len};
+ va_list argp;
+ va_start(argp, fmt);
+ ret = __printf_internal(fmt, argp, backend_buf, &ptrs);
+ va_end(argp);
+ if (ptrs[0] < ptrs[1]) *ptrs[0] = '\0';
+ return ret;
+}
+
+
int file_open(libc_file *f, const char *path, int flags) {
f->pos = 0;
f->eof = false;