commit 02de696536dc94170e76491133e6fec619f99fcb
parent c7a4a58d2cf685423c4ee3a83f0e171416c616a2
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Sat, 19 Dec 2015 16:08:11 +0100
Adding support for reading logs from standard input
Diffstat:
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -111,9 +111,16 @@ int main (int argc, char *argv[]) {
results.fileName = intputFile;
results.fileSize = (uint64_t)logFileSize.st_size;
- if (!(logFile = fopen(intputFile, "r"))) {
- perror("Can't open log file");
- return EXIT_FAILURE;
+ /* Open log file */
+ if (!strcmp(intputFile, "-")) {
+ /* Read from standard input */
+ logFile = stdin;
+ } else {
+ /* Attempt to read from file */
+ if (!(logFile = fopen(intputFile, "r"))) {
+ perror("Can't open log file");
+ return EXIT_FAILURE;
+ }
}
while (fgets(lineBuffer, LINE_MAX_LENGTH, logFile) != NULL) {