aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-09-24 01:39:56 +0200
committerRon Evans <[email protected]>2021-10-26 17:08:30 +0200
commit14bb90c3c0f59b752cd4017648521b9adcfeb013 (patch)
tree3816fe95aae891c160213a2a2f8359015ec36919 /lib
parent1645f45c1a42c57426017741643caebfaabc19ea (diff)
downloadtinygo-14bb90c3c0f59b752cd4017648521b9adcfeb013.tar.gz
tinygo-14bb90c3c0f59b752cd4017648521b9adcfeb013.zip
cgo: add support for stdio in picolibc and wasi-libc
This adds support for stdio in picolibc and fixes wasm_exec.js so that it can also support C puts. With this, C stdout works on all supported platforms.
Diffstat (limited to 'lib')
m---------lib/picolibc0
-rw-r--r--lib/picolibc-stdio.c18
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/picolibc b/lib/picolibc
-Subproject 80528c684b10aaee977397e7eb40c4784e6dc43
+Subproject f68b8204f797d6b3bfbc7c4da4d257961fbc877
diff --git a/lib/picolibc-stdio.c b/lib/picolibc-stdio.c
new file mode 100644
index 000000000..1d7514ba2
--- /dev/null
+++ b/lib/picolibc-stdio.c
@@ -0,0 +1,18 @@
+// This file is included in the picolibc build.
+// It makes stdio functions available to the C library.
+
+#include <stdio.h>
+#include <sys/cdefs.h>
+
+// Defined in the runtime package. Writes to the default console (usually, the
+// first UART or an USB-CDC device).
+int runtime_putchar(char, FILE*);
+
+// Define stdin, stdout, and stderr as a single object.
+// This object must not reside in ROM.
+static FILE __stdio = FDEV_SETUP_STREAM(runtime_putchar, NULL, NULL, _FDEV_SETUP_WRITE);
+
+// Define the underlying structs for stdin, stdout, and stderr.
+FILE *const stdin = &__stdio;
+__strong_reference(stdin, stdout);
+__strong_reference(stdin, stderr);