]>
git.scottworley.com Git - tl-append/blob - tl-append.c
4 const char *FILENAME
= "tl.log";
5 const size_t BUF_SIZE
= 1024;
7 static void die(const char *message
) {
8 fputs(message
, stderr
);
13 static void die_err(const char *message
) {
18 static void read_line(char *buf
) {
19 if (fgets(buf
, BUF_SIZE
, stdin
) == NULL
) {
21 die("I/O error reading line");
23 buf
[0] = '\0'; /* Unclear if fgets does this already */
26 die("Unexpected error reading line");
30 static void write_line(const char *line
) {
31 FILE *f
= fopen(FILENAME
, "a");
33 die_err("Error opening output file");
34 if (fputs(line
, f
) == EOF
)
35 die("Error writing to output file");
37 die_err("Error closing output file");
42 for (read_line(buf
); buf
[0]; read_line(buf
)) {