+#define _POSIX_C_SOURCE 2
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void die(const char *message) {
+ fputs(message, stderr);
+ fputc('\n', stderr);
+ exit(1);
+}
+
+static void die_err(const char *message) {
+ perror(message);
+ exit(1);
+}
+
+static void write_and_read_line() {
+ char buf[10];
+
+ FILE *p = popen("./tl-append", "w");
+ if (p == NULL)
+ die_err("Couldn't run tl-append");
+ if (fputs("foo\n", p) == EOF)
+ die("Couldn't write to pipe");
+ int status = pclose(p);
+ if (status < 0)
+ die_err("Error closing pipe");
+ if (status != 0)
+ die("tl-append exited abnormally");
+
+ FILE *f = fopen("tl.log", "r");
+ if (f == NULL)
+ die_err("Error opening log file");
+ if (fgets(buf, sizeof(buf), f) == NULL)
+ die("Error reading log file");
+ if (strncmp("foo\n", buf, sizeof(buf)) != 0)
+ die("Wrong contents in log file");
+ if (fclose(f) != 0)
+ die_err("Error closing log file");
+}
+
+int main() { write_and_read_line(); }