chiark / gitweb /
Remove src/tty-ask-password-agent
[elogind.git] / src / udev / v4l_id / v4l_id.c
1 /*
2  * Copyright (C) 2009 Kay Sievers <kay@vrfy.org>
3  * Copyright (c) 2009 Filippo Argiolas <filippo.argiolas@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details:
14  */
15
16 #include <stdio.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <ctype.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <getopt.h>
24 #include <sys/types.h>
25 #include <sys/time.h>
26 #include <sys/ioctl.h>
27 #include <linux/videodev2.h>
28
29 #include "util.h"
30
31 int main(int argc, char *argv[]) {
32         static const struct option options[] = {
33                 { "help", no_argument, NULL, 'h' },
34                 {}
35         };
36         _cleanup_close_ int fd = -1;
37         char *device;
38         struct v4l2_capability v2cap;
39         int c;
40
41         while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
42
43                 switch (c) {
44                 case 'h':
45                         printf("%s [-h,--help] <device file>\n\n"
46                                "Video4Linux device identification.\n\n"
47                                "  -h  Print this message\n"
48                                , program_invocation_short_name);
49                         return 0;
50                 case '?':
51                         return -EINVAL;
52
53                 default:
54                         assert_not_reached("Unhandled option");
55                 }
56
57         device = argv[optind];
58         if (device == NULL)
59                 return 2;
60
61         fd = open(device, O_RDONLY);
62         if (fd < 0)
63                 return 3;
64
65         if (ioctl(fd, VIDIOC_QUERYCAP, &v2cap) == 0) {
66                 printf("ID_V4L_VERSION=2\n");
67                 printf("ID_V4L_PRODUCT=%s\n", v2cap.card);
68                 printf("ID_V4L_CAPABILITIES=:");
69                 if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0)
70                         printf("capture:");
71                 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0)
72                         printf("video_output:");
73                 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0)
74                         printf("video_overlay:");
75                 if ((v2cap.capabilities & V4L2_CAP_AUDIO) > 0)
76                         printf("audio:");
77                 if ((v2cap.capabilities & V4L2_CAP_TUNER) > 0)
78                         printf("tuner:");
79                 if ((v2cap.capabilities & V4L2_CAP_RADIO) > 0)
80                         printf("radio:");
81                 printf("\n");
82         }
83
84         return 0;
85 }