]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/udev/v4l_id/v4l_id.c
util-lib: split out fd-related operations into fd-util.[ch]
[thirdparty/systemd.git] / src / udev / v4l_id / v4l_id.c
CommitLineData
c5a9680e 1/*
1298001e 2 * Copyright (C) 2009 Kay Sievers <kay@vrfy.org>
c5a9680e
KS
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>
c5a9680e 21#include <unistd.h>
c5a9680e
KS
22#include <fcntl.h>
23#include <getopt.h>
24#include <sys/types.h>
25#include <sys/time.h>
26#include <sys/ioctl.h>
c5a9680e
KS
27#include <linux/videodev2.h>
28
3ffd4af2 29#include "fd-util.h"
5ac0162c
LP
30#include "util.h"
31
32int main(int argc, char *argv[]) {
912541b0
KS
33 static const struct option options[] = {
34 { "help", no_argument, NULL, 'h' },
35 {}
36 };
5ac0162c 37 _cleanup_close_ int fd = -1;
912541b0
KS
38 char *device;
39 struct v4l2_capability v2cap;
fadce6ca 40 int c;
c5a9680e 41
fadce6ca 42 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
c5a9680e 43
fadce6ca 44 switch (c) {
912541b0 45 case 'h':
5ac0162c
LP
46 printf("%s [-h,--help] <device file>\n\n"
47 "Video4Linux device identification.\n\n"
48 " -h Print this message\n"
49 , program_invocation_short_name);
912541b0 50 return 0;
fadce6ca
ZJS
51 case '?':
52 return -EINVAL;
53
912541b0 54 default:
fadce6ca 55 assert_not_reached("Unhandled option");
912541b0 56 }
c5a9680e 57
fadce6ca 58 device = argv[optind];
912541b0
KS
59 if (device == NULL)
60 return 2;
fadce6ca 61
5ac0162c 62 fd = open(device, O_RDONLY);
912541b0
KS
63 if (fd < 0)
64 return 3;
c5a9680e 65
5ac0162c 66 if (ioctl(fd, VIDIOC_QUERYCAP, &v2cap) == 0) {
912541b0
KS
67 printf("ID_V4L_VERSION=2\n");
68 printf("ID_V4L_PRODUCT=%s\n", v2cap.card);
69 printf("ID_V4L_CAPABILITIES=:");
70 if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0)
71 printf("capture:");
72 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0)
73 printf("video_output:");
74 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0)
75 printf("video_overlay:");
76 if ((v2cap.capabilities & V4L2_CAP_AUDIO) > 0)
77 printf("audio:");
78 if ((v2cap.capabilities & V4L2_CAP_TUNER) > 0)
79 printf("tuner:");
80 if ((v2cap.capabilities & V4L2_CAP_RADIO) > 0)
81 printf("radio:");
82 printf("\n");
83 }
c5a9680e 84
912541b0 85 return 0;
c5a9680e 86}