]>
git.scottworley.com Git - tl-append/blob - tl-append.c
f8bacdd03ccdd94e2de904bb546a7fd79245be69
6 const size_t BUF_SIZE
= 1024;
8 static void read_line(char *buf
) {
9 if (fgets(buf
, BUF_SIZE
, stdin
) == NULL
) {
11 die("I/O error reading line");
13 buf
[0] = '\0'; /* Unclear if fgets does this already */
16 die("Unexpected error reading line");
20 static void write_line(const char *line
) {
21 const char *now
= encode_time(time(NULL
));
22 FILE *f
= fopen(FILENAME
, "a");
24 die_err("Error opening output file");
25 if (fputs(now
, f
) == EOF
)
26 die("Error writing to output file");
27 if (fputc(' ', f
) == EOF
)
28 die("Error writing to output file");
29 if (fputs(line
, f
) == EOF
)
30 die("Error writing to output file");
32 die_err("Error closing output file");
37 for (read_line(buf
); buf
[0]; read_line(buf
)) {