[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 2/2] Send usage output to stdout or stderr depending on context



If usage information is displayed because of an error, it should go to stderr.
If it is displayed because the -h option was given it should go to stdout.
---
 helper/main.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/helper/main.c b/helper/main.c
index d258381..81bb717 100644
--- a/helper/main.c
+++ b/helper/main.c
@@ -55,9 +55,10 @@ static const struct option long_options[] = {
 };
 
 static void
-usage (const char *progname)
+usage (FILE *f, const char *progname)
 {
-  printf ("%s: build the supermin appliance on the fly\n"
+  fprintf (f,
+          "%s: build the supermin appliance on the fly\n"
           "\n"
           "Usage:\n"
           "  %s [-options] inputs [...] host_cpu kernel initrd\n"
@@ -103,7 +104,7 @@ parseint (const char *id, const char *progname)
   long int val = strtol (id, &invalid, 10);
   if (*invalid != '\0') {
     fprintf (stderr, "%s is not a valid uid\n", id);
-    usage (progname);
+    usage (stderr, progname);
     exit (EXIT_FAILURE);
   }
   return val;
@@ -169,7 +170,7 @@ main (int argc, char *argv[])
 
     switch (c) {
     case HELP_OPTION:
-      usage (argv[0]);
+      usage (stdout, argv[0]);
       exit (EXIT_SUCCESS);
 
     case 'f':
@@ -197,7 +198,7 @@ main (int argc, char *argv[])
       exit (EXIT_SUCCESS);
 
     default:
-      usage (argv[0]);
+      usage (stderr, argv[0]);
       exit (EXIT_FAILURE);
     }
   }

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]