clean some stuff up
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,4 +1,4 @@
|
|||||||
CFLAGS=--std=c99 -O2 -Wall -Wextra -pedantic
|
CFLAGS=--std=c99 -O2 -Wall -Wextra -Werror -pedantic
|
||||||
|
|
||||||
annotate: annotate.o
|
annotate: annotate.o
|
||||||
|
|
||||||
|
|||||||
17
annotate.c
17
annotate.c
@@ -1,10 +1,10 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define BUF_SIZE 1024
|
#define BUF_SIZE 1024
|
||||||
#define PRINT_BUF_SIZE 1280
|
|
||||||
|
|
||||||
void print_now() {
|
void print_now() {
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -12,6 +12,11 @@ void print_now() {
|
|||||||
|
|
||||||
struct tm *time_parts = localtime(&now);
|
struct tm *time_parts = localtime(&now);
|
||||||
|
|
||||||
|
if (!time_parts) {
|
||||||
|
perror("Error getting time");
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
printf("[%d-%02d-%02d %02d:%02d:%02d] ",
|
printf("[%d-%02d-%02d %02d:%02d:%02d] ",
|
||||||
time_parts->tm_year + 1900,
|
time_parts->tm_year + 1900,
|
||||||
time_parts->tm_mon + 1,
|
time_parts->tm_mon + 1,
|
||||||
@@ -28,7 +33,6 @@ void print_now() {
|
|||||||
int main() {
|
int main() {
|
||||||
char buffer[BUF_SIZE];
|
char buffer[BUF_SIZE];
|
||||||
|
|
||||||
|
|
||||||
// when true, print the time on the next iteration
|
// when true, print the time on the next iteration
|
||||||
// allows us to avoid printing after the last newline
|
// allows us to avoid printing after the last newline
|
||||||
bool output_time = true;
|
bool output_time = true;
|
||||||
@@ -43,7 +47,10 @@ int main() {
|
|||||||
|
|
||||||
if (buffer[i] == '\n') {
|
if (buffer[i] == '\n') {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fflush(stdout);
|
if (fflush(stdout) == EOF) {
|
||||||
|
perror("Unable to flush stdout");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
output_time = true;
|
output_time = true;
|
||||||
} else {
|
} else {
|
||||||
fputc(buffer[i], stdout);
|
fputc(buffer[i], stdout);
|
||||||
@@ -53,7 +60,7 @@ int main() {
|
|||||||
|
|
||||||
if (count_read < 0) {
|
if (count_read < 0) {
|
||||||
perror("Error reading from stdin");
|
perror("Error reading from stdin");
|
||||||
return 1;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|||||||
Reference in New Issue
Block a user