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