[pisa-src] r1726 - trunk/test/ifaddr.c

  • From: Diego Biurrun <diego@xxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Thu, 19 Nov 2009 16:16:56 +0100

Author: biurrun
Date: Thu Nov 19 16:16:56 2009
New Revision: 1726

Log:
Refactor test if the program was passed the right number of parameters.

Modified:
   trunk/test/ifaddr.c

Modified: trunk/test/ifaddr.c
==============================================================================
--- trunk/test/ifaddr.c Thu Nov 19 16:09:28 2009        (r1725)
+++ trunk/test/ifaddr.c Thu Nov 19 16:16:56 2009        (r1726)
@@ -90,28 +90,17 @@
        return 0;
 }
 
-static void usage(const char *cmdname)
-{
-       fprintf(stderr,
-               "Usage: %s [ifname]\n", cmdname);
-}
-
 int main(int argc, char *argv[])
 {
        char ifname[IFNAMSIZ] = "eth0";
 
-       if (argc == 2) {
-               if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 
0) {
-                       usage(argv[0]);
-                       exit(EXIT_FAILURE);
-               }
-               strncpy(ifname, argv[1], IFNAMSIZ);
-       }
-       else if (argc > 2) {
-               usage(argv[0]);
+       if (argc != 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], 
"--help") == 0) {
+               fprintf(stderr, "Usage: %s [ifname]\n", argv[0]);
                exit(EXIT_FAILURE);
        }
 
+       strncpy(ifname, argv[1], IFNAMSIZ);
+
        if (print_ifaddr(ifname) < 0)
                return -1;
 

Other related posts:

  • » [pisa-src] r1726 - trunk/test/ifaddr.c - Diego Biurrun