commit 4926e536c96ec95b47c4457adc16a182842ce862
parent 3422713679c8528a5feedb1b170c1a55adb1ab0f
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Tue, 23 Dec 2025 15:36:43 +0000
Convert echo to .cpp
Diffstat:
| D | echo.c | | | 39 | --------------------------------------- |
| A | echo.cpp | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 42 insertions(+), 39 deletions(-)
diff --git a/echo.c b/echo.c
@@ -1,39 +0,0 @@
-#include "linux.h"
-
-static struct
-{
- unsigned short size;
- char data[0x1000 - sizeof(unsigned short)];
-} buf;
-
-static void putflush()
-{
- if (buf.size && write(1, buf.data, buf.size) != buf.size)
- exit(1);
- buf.size = 0;
-}
-
-static void putch(char c)
-{
- buf.data[buf.size++] = c;
- if (c == '\n' || buf.size == sizeof buf.data)
- putflush();
-}
-
-static void putstr(char const* s)
-{
- while(*s)
- putch(*s++);
-}
-
-int main(int argc, char* argv[])
-{
- if (argc > 1)
- putstr(argv[1]);
- for (int i = 2; i < argc; ++i)
- {
- putch(' ');
- putstr(argv[i]);
- }
- putch('\n');
-}
diff --git a/echo.cpp b/echo.cpp
@@ -0,0 +1,42 @@
+#include "linux.hpp"
+
+static struct
+{
+ unsigned short size;
+ char data[0x1000 - sizeof(unsigned short)];
+} buf;
+
+static void putflush()
+{
+ if (!buf.size)
+ return;
+ auto res = write(stdout, buf.data, buf.size);
+ if (!res or *res != buf.size)
+ exit(1);
+ buf.size = 0;
+}
+
+static void putch(char c)
+{
+ buf.data[buf.size++] = c;
+ if (c == '\n' || buf.size == sizeof buf.data)
+ putflush();
+}
+
+static void putstr(char const* s)
+{
+ while(*s)
+ putch(*s++);
+}
+
+int main(int argc, char* argv[])
+{
+ if (argc > 1)
+ putstr(argv[1]);
+ for (int i = 2; i < argc; ++i)
+ {
+ putch(' ');
+ putstr(argv[i]);
+ }
+ putch('\n');
+}