chiark / gitweb /
v4l_id: use standard option parsing loop
[elogind.git] / src / udev / v4l_id / v4l_id.c
index 0ebe43463992208ef1b28774c02d06e58c5487ab..5c57db44c161be5a0f629be57623c3d57a3074ea 100644 (file)
@@ -36,29 +36,28 @@ int main(int argc, char *argv[]) {
         _cleanup_close_ int fd = -1;
         char *device;
         struct v4l2_capability v2cap;
+        int c;
 
-        for (;;) {
-                int option;
+        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
 
-                option = getopt_long(argc, argv, "h", options, NULL);
-                if (option == -1)
-                        break;
-
-                switch (option) {
+                switch (c) {
                 case 'h':
                         printf("%s [-h,--help] <device file>\n\n"
                                "Video4Linux device identification.\n\n"
                                "  -h  Print this message\n"
                                , program_invocation_short_name);
                         return 0;
+                case '?':
+                        return -EINVAL;
+
                 default:
-                        return 1;
+                        assert_not_reached("Unhandled option");
                 }
-        }
-        device = argv[optind];
 
+        device = argv[optind];
         if (device == NULL)
                 return 2;
+
         fd = open(device, O_RDONLY);
         if (fd < 0)
                 return 3;