summaryrefslogtreecommitdiffstats
path: root/tools/include/nolibc
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2022-02-07 17:23:30 +0100
committerPaul E. McKenney <paulmck@kernel.org>2022-04-20 17:05:44 -0700
commit4e383a66acfe16827ce7fbc0e60c56782a83fc92 (patch)
tree24e766715e0ac3a1066ff9f36c0fa445669267dd /tools/include/nolibc
parent5f493178ef3187b939d3068563e5da6045085c2a (diff)
downloadlinux-4e383a66acfe16827ce7fbc0e60c56782a83fc92.tar.bz2
tools/nolibc/stdio: add a minimal set of stdio functions
This only provides getchar(), putchar(), and puts(). Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools/include/nolibc')
-rw-r--r--tools/include/nolibc/nolibc.h1
-rw-r--r--tools/include/nolibc/stdio.h57
2 files changed, 58 insertions, 0 deletions
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index a349c88c45ff..7eaa09fe9f4d 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -88,6 +88,7 @@
#include "types.h"
#include "sys.h"
#include "ctype.h"
+#include "stdio.h"
#include "stdlib.h"
#include "string.h"
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
new file mode 100644
index 000000000000..4c6af3016e2e
--- /dev/null
+++ b/tools/include/nolibc/stdio.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * minimal stdio function definitions for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_STDIO_H
+#define _NOLIBC_STDIO_H
+
+#include "std.h"
+#include "arch.h"
+#include "types.h"
+#include "sys.h"
+#include "stdlib.h"
+#include "string.h"
+
+#ifndef EOF
+#define EOF (-1)
+#endif
+
+static __attribute__((unused))
+int getchar(void)
+{
+ unsigned char ch;
+
+ if (read(0, &ch, 1) <= 0)
+ return EOF;
+ return ch;
+}
+
+static __attribute__((unused))
+int putchar(int c)
+{
+ unsigned char ch = c;
+
+ if (write(1, &ch, 1) <= 0)
+ return EOF;
+ return ch;
+}
+
+static __attribute__((unused))
+int puts(const char *s)
+{
+ size_t len = strlen(s);
+ ssize_t ret;
+
+ while (len > 0) {
+ ret = write(1, s, len);
+ if (ret <= 0)
+ return EOF;
+ s += ret;
+ len -= ret;
+ }
+ return putchar('\n');
+}
+
+#endif /* _NOLIBC_STDIO_H */