aboutsummaryrefslogtreecommitdiff
path: root/lib/io/io.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2022-12-15 22:46:25 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2022-12-15 22:46:25 +0100
commitb9038b1c6b31a8f8d6b8b648cee0cf3b457dc24c (patch)
treed967cf38fba25c1a3eed621026f37891bba8f191 /lib/io/io.c
parent02062f0cf84e1cb7fb294de54b0c00db6323c529 (diff)
first version of io and wstdf
Diffstat (limited to 'lib/io/io.c')
-rw-r--r--lib/io/io.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/io/io.c b/lib/io/io.c
new file mode 100644
index 0000000..41cd3e0
--- /dev/null
+++ b/lib/io/io.c
@@ -0,0 +1,50 @@
+#include "io.h"
+
+#include "../cstr/cstr.h"
+
+void __wstdn(const char *buf, u64 n)
+{
+ write(STDOUT_FD, buf, n);
+}
+
+
+void wstd(const char *buf)
+{
+ __wstdn(buf, cstr_length(buf));
+}
+
+
+void rstd(char *buf, unsigned long count)
+{
+ read(STDIN_FD, buf, count);
+}
+
+void wstdf__(const char *buf, void **args)
+{
+ const char *start = buf;
+ for (; *buf; ++buf) {
+ if (*buf == '%') {
+ if (buf - start > 0)
+ __wstdn(start, buf - start);
+
+ ++buf;
+
+ switch (*buf) {
+ case '%': __wstdn("%", 1); break;
+ case 's':
+ __wstdn(((const char **)args)[0], cstr_length(((const char**)args)[0]));
+ ++args; break;
+ }
+
+ start = buf + 1;
+ }
+ }
+
+ if (buf - start > 0)
+ __wstdn(start, buf - start);
+}
+
+int main() {
+ void *args[] = { "hallo", "welt" };
+ wstdf__("%s %s\n", args);
+}