Skip to content

Commit

Permalink
exit with error if fflush() fail
Browse files Browse the repository at this point in the history
Tested with closed stdout. Mentioned in #2.
  • Loading branch information
Andreas Lundin committed Sep 19, 2023
1 parent 778b542 commit 70343ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion output.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#include <sys/time.h>

#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <pcap.h>
Expand Down Expand Up @@ -203,7 +205,10 @@ print_stats(int unused)
}

fprintf(stdout, "\n");
fflush(stdout);
if (fflush(stdout) == EOF) {
fprintf(stderr, "Error: Couldn't write to stdout: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (announceCount == FLG_CNT)
exit(EXIT_SUCCESS);
Expand Down

0 comments on commit 70343ab

Please sign in to comment.