Skip to content

cpu/native: implement fputs and fwrite#21912

Merged
maribu merged 2 commits intoRIOT-OS:masterfrom
mguetschow:native-fputs-fwrite
Nov 24, 2025
Merged

cpu/native: implement fputs and fwrite#21912
maribu merged 2 commits intoRIOT-OS:masterfrom
mguetschow:native-fputs-fwrite

Conversation

@mguetschow
Copy link
Copy Markdown
Contributor

Contribution description

Implement fputs and fwrite explicitly for cpu/native, so it will be passed through _native_write instead of calling into the (linked-in) C library, which would somehow end up in a different stdout.

Testing procedure

diff --git a/examples/basic/hello-world/Makefile b/examples/basic/hello-world/Makefile
index ad1fa6fdcb..14dbbb2fdd 100644
--- a/examples/basic/hello-world/Makefile
+++ b/examples/basic/hello-world/Makefile
@@ -12,6 +12,8 @@ RIOTBASE ?= $(CURDIR)/../../..
 # development process:
 DEVELHELP ?= 1
 
+USEMODULE += ztimer_msec
+
 # Change this to 0 show compiler invocation lines by default:
 QUIET ?= 1
 
diff --git a/examples/basic/hello-world/main.c b/examples/basic/hello-world/main.c
index c1fe9bae12..811ce82352 100644
--- a/examples/basic/hello-world/main.c
+++ b/examples/basic/hello-world/main.c
@@ -18,6 +18,8 @@
 
 #include <stdio.h>
 
+#include "ztimer.h"
+
 int main(void)
 {
     puts("Hello World!");
@@ -25,5 +27,13 @@ int main(void)
     printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
     printf("This board features a(n) %s CPU.\n", RIOT_CPU);
 
+    while (1) {
+        fprintf(stdout, "fprintf - ");
+        printf("printf - ");
+        fputs("fputs - ", stdout);
+        puts("puts");
+        ztimer_sleep(ZTIMER_MSEC, 1000);
+    }
+
     return 0;
 }

on master

$ make -C examples/basic/hello-world flash cleanterm
/home/mikolai/TUD/Code/RIOT/examples/basic/hello-world/bin/native64/hello-world.elf  tap0 
...
printf - puts
printf - puts
printf - puts
^C
native: exiting
fprintf - fputs - fprintf - fputs - fprintf - fputs - 

with this PR

$ make -C examples/basic/hello-world flash term
...
fprintf - printf - fputs - puts
fprintf - printf - fputs - puts
fprintf - printf - fputs - puts

Issues/PRs references

Fixes #21910

@github-actions github-actions bot added Platform: native Platform: This PR/issue effects the native platform Area: cpu Area: CPU/MCU ports labels Nov 24, 2025
@crasbe crasbe added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 24, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Nov 24, 2025

Murdock results

✔️ PASSED

bb192ee cpu/native: implement fputc, too

Success Failures Total Runtime
10932 0 10932 12m:49s

Artifacts

@maribu maribu added this pull request to the merge queue Nov 24, 2025
Merged via the queue into RIOT-OS:master with commit ac7dccf Nov 24, 2025
28 checks passed
@mguetschow
Copy link
Copy Markdown
Contributor Author

Thanks :)

@mguetschow mguetschow deleted the native-fputs-fwrite branch November 25, 2025 09:00
@leandrolanzieri leandrolanzieri added this to the Release 2026.01 milestone Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

native: fputs and fprintf not printed correctly

5 participants