add run wrapper, move t_printf and t_status into separate translation unit
[libc-test] / src / common / print.c
diff --git a/src/common/print.c b/src/common/print.c
new file mode 100644 (file)
index 0000000..45a4fd5
--- /dev/null
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+volatile int t_status = 0;
+
+int t_printf(const char *s, ...)
+{
+       va_list ap;
+       char buf[512];
+       int n;
+
+       t_status = 1;
+       va_start(ap, s);
+       n = vsnprintf(buf, sizeof buf, s, ap);
+       va_end(ap);
+       if (n < 0)
+               n = 0;
+       else if (n >= sizeof buf) {
+               n = sizeof buf;
+               buf[n - 1] = '\n';
+               buf[n - 2] = '.';
+               buf[n - 3] = '.';
+               buf[n - 4] = '.';
+       }
+       return write(1, buf, n);
+}