aboutsummaryrefslogtreecommitdiff
path: root/include/io.h
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-03-20 02:34:01 +0100
committerjohannst <johannes.stoelp@gmail.com>2021-03-20 02:34:01 +0100
commitef6a411ce8ff615d65e2be105834c2fdbe557de1 (patch)
tree3336df00ca14b6783486188fed5b4dde5df6cec3 /include/io.h
parent3cbf2298b2b3dc24355449131d2e496f8e02b8f5 (diff)
downloaddynld-ef6a411ce8ff615d65e2be105834c2fdbe557de1.tar.gz
dynld-ef6a411ce8ff615d65e2be105834c2fdbe557de1.zip
Split common headers in header/src files.
Diffstat (limited to 'include/io.h')
-rw-r--r--include/io.h45
1 files changed, 0 insertions, 45 deletions
diff --git a/include/io.h b/include/io.h
deleted file mode 100644
index 4f61cbf..0000000
--- a/include/io.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2020 Johannes Stoelp
-
-#pragma once
-
-#include "fmt.h"
-#include "syscall.h"
-
-#include <asm/unistd.h>
-
-// `pfmt` uses fixed-size buffer on the stack for formating the message
-// (for simplicity and since we don't impl buffered I/O).
-//
-// Size can be re-configured by defining `MAX_PRINTF_LEN` before including
-// `io.h`.
-//
-// NOTE: This allows to specify a large buffer on the stack, but for
-// the purpose of this study that's fine, we are cautious.
-#if !defined(MAX_PRINTF_LEN)
-# define MAX_PRINTF_LEN 128
-#elif MAX_PRINTF_LEN > 512
-# error MAX_PRINTF_LEN is limited by 512!
-#endif
-
-#define FD_STDOUT 1
-#define FD_STDERR 2
-
-static int pfmt(const char* fmt, ...) {
- char buf[MAX_PRINTF_LEN];
-
- va_list ap;
- va_start(ap, fmt);
- int ret = vfmt(buf, sizeof(buf), fmt, ap);
- va_end(ap);
-
- if (ret > MAX_PRINTF_LEN - 1) {
- syscall3(__NR_write, FD_STDERR, buf, MAX_PRINTF_LEN - 1);
-
- static const char warn[] = "\npfmt: Message truncated, max length can be configured by defining MAX_PRINTF_LEN\n";
- syscall3(__NR_write, FD_STDOUT, warn, sizeof(warn));
- return MAX_PRINTF_LEN - 1;
- }
-
- syscall3(__NR_write, FD_STDOUT, buf, ret);
- return ret;
-}