Add support for --stdout to unzck
authorJonathan Dieter <jdieter@gmail.com>
Fri, 22 Jun 2018 11:04:41 +0000 (14:04 +0300)
committerJonathan Dieter <jdieter@gmail.com>
Fri, 22 Jun 2018 11:04:41 +0000 (14:04 +0300)
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
src/unzck.c

index 816c0dc74dccde658b8298043422b18f7d98275a..ff8f2dbf9ad1f0b98a516eb6b220295d8a4c879e 100644 (file)
@@ -45,6 +45,7 @@ static struct argp_option options[] = {
     {"verbose", 'v', 0,        0,
      "Increase verbosity (can be specified more than once for debugging)"},
     {"quiet",   'q', 0,        0, "Only show errors"},
+    {"stdout",  'c', 0,        0, "Direct output to stdout"},
     {"version", 'V', 0,        0, "Show program version"},
     { 0 }
 };
@@ -52,6 +53,7 @@ static struct argp_option options[] = {
 struct arguments {
   char *args[1];
   zck_log_type log_level;
+  int stdout;
 };
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state) {
@@ -66,6 +68,9 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
         case 'q':
             arguments->log_level = ZCK_LOG_ERROR;
             break;
+        case 'c':
+            arguments->stdout = 1;
+            break;
         case 'V':
             version();
             break;
@@ -114,12 +119,15 @@ int main (int argc, char *argv[]) {
     char *out_name = malloc(strlen(arguments.args[0]) - 3);
     snprintf(out_name, strlen(arguments.args[0]) - 3, "%s", arguments.args[0]);
 
-    int dst_fd = open(out_name, O_TRUNC | O_WRONLY | O_CREAT, 0644);
-    if(dst_fd < 0) {
-        printf("Unable to open %s", out_name);
-        perror("");
-        free(out_name);
-        exit(1);
+    int dst_fd = STDOUT_FILENO;
+    if(!arguments.stdout) {
+        dst_fd = open(out_name, O_TRUNC | O_WRONLY | O_CREAT, 0644);
+        if(dst_fd < 0) {
+            printf("Unable to open %s", out_name);
+            perror("");
+            free(out_name);
+            exit(1);
+        }
     }
 
     int good_exit = False;