diff --git a/Makefile b/Makefile index e9602b0..8ab585a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS=--std=c99 -O2 -Wall -Wextra -pedantic +CFLAGS=--std=c99 -O2 -Wall -Wextra -Werror -pedantic annotate: annotate.o diff --git a/annotate.c b/annotate.c index ec06730..f70601c 100644 --- a/annotate.c +++ b/annotate.c @@ -1,10 +1,10 @@ -#include #include +#include +#include #include #include #define BUF_SIZE 1024 -#define PRINT_BUF_SIZE 1280 void print_now() { time_t now; @@ -12,6 +12,11 @@ void print_now() { struct tm *time_parts = localtime(&now); + if (!time_parts) { + perror("Error getting time"); + exit(3); + } + printf("[%d-%02d-%02d %02d:%02d:%02d] ", time_parts->tm_year + 1900, time_parts->tm_mon + 1, @@ -28,7 +33,6 @@ void print_now() { int main() { char buffer[BUF_SIZE]; - // when true, print the time on the next iteration // allows us to avoid printing after the last newline bool output_time = true; @@ -43,7 +47,10 @@ int main() { if (buffer[i] == '\n') { printf("\n"); - fflush(stdout); + if (fflush(stdout) == EOF) { + perror("Unable to flush stdout"); + exit(2); + } output_time = true; } else { fputc(buffer[i], stdout); @@ -53,7 +60,7 @@ int main() { if (count_read < 0) { perror("Error reading from stdin"); - return 1; + exit(1); } fflush(stdout);