Accept files as command line arguments again in rpmdeps (RhBug:807767)
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 29 Mar 2012 08:26:57 +0000 (11:26 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 29 Mar 2012 08:26:57 +0000 (11:26 +0300)
- Commit a25c3c7bac95ab7eb55f0ecf0b8793d8da341611 removed what was
  supposedly a non-supported method of passing files as arguments
  (instead of the normal stdin method) to rpmdeps. Turns out
  rpmdeps is even documented to take files as cli args, and that's
  how Fedora's %filter_setup macros are calling it...
- Allow files as arguments again, but in a way that doesn't cause
  argvFoo() vs popt crash-n-burn.

tools/rpmdeps.c

index 6b0b527..c3112eb 100644 (file)
@@ -60,11 +60,19 @@ main(int argc, char *argv[])
     if (optCon == NULL)
        goto exit;
 
-    while (fgets(buf, sizeof(buf), stdin) != NULL) {
-       char *be = buf + strlen(buf) - 1;
-       while (strchr("\r\n", *be) != NULL)
-           *be-- = '\0';
-       argvAdd(&av, buf);
+    /* normally files get passed through stdin but also accept files as args */
+    if (poptPeekArg(optCon)) {
+       const char *arg;
+       while ((arg = poptGetArg(optCon)) != NULL) {
+           argvAdd(&av, arg);
+       }
+    } else {
+       while (fgets(buf, sizeof(buf), stdin) != NULL) {
+           char *be = buf + strlen(buf) - 1;
+           while (strchr("\r\n", *be) != NULL)
+               *be-- = '\0';
+           argvAdd(&av, buf);
+       }
     }
     /* Make sure file names are sorted. */
     argvSort(av, NULL);