liblinux++

A hosted C++ runtime without any libc.
git clone git://henryandlizzy.uk/liblinux++
Log | Files | Refs

echo.cpp (611B)


      1 #include "linux.hpp"
      2 
      3 static struct
      4 {
      5 	unsigned short size;
      6 	char data[0x1000 - sizeof(unsigned short)];
      7 } buf;
      8 
      9 static void putflush()
     10 {
     11 	if (!buf.size)
     12 		return;
     13 	auto res = write(stdout, buf.data, buf.size);
     14 	if (!res or *res != buf.size)
     15 		exit(1);
     16 	buf.size = 0;
     17 }
     18 
     19 static void putch(char c)
     20 {
     21 	buf.data[buf.size++] = c;
     22 	if (c == '\n' || buf.size == sizeof buf.data)
     23 		putflush();
     24 }
     25 
     26 static void putstr(char const* s)
     27 {
     28 	while(*s)
     29 		putch(*s++);
     30 }
     31 
     32 int main(int argc, char* argv[])
     33 {
     34 	if (argc > 1)
     35 		putstr(argv[1]);
     36 	for (int i = 2; i < argc; ++i)
     37 	{
     38 		putch(' ');
     39 		putstr(argv[i]);
     40 	}
     41 	putch('\n');
     42 }