~oif-packaging/evemu/oneiric

« back to all changes in this revision

Viewing changes to tools/evemu-describe.c

  • Committer: Francis Ginther
  • Date: 2012-08-20 16:17:58 UTC
  • mfrom: (0.1.32 1.0.5)
  • mto: (14.1.2 oneiric)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: francis.ginther@canonical.com-20120820161758-5ht9bd2rgdg3v6hj
Tags: upstream-1.0.5.1
ImportĀ upstreamĀ versionĀ 1.0.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *
 
3
 * evemu - Kernel device emulation
 
4
 *
 
5
 * Copyright (C) 2010, 2011 Canonical Ltd.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation, either version 3 of the License, or (at your
 
10
 * 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
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
 
21
 *
 
22
 * Permission is hereby granted, free of charge, to any person obtaining a
 
23
 * copy of this software and associated documentation files (the "Software"),
 
24
 * to deal in the Software without restriction, including without limitation
 
25
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
26
 * and/or sell copies of the Software, and to permit persons to whom the
 
27
 * Software is furnished to do so, subject to the following conditions:
 
28
 *
 
29
 * The above copyright notice and this permission notice (including the next
 
30
 * paragraph) shall be included in all copies or substantial portions of the
 
31
 * Software.
 
32
 *
 
33
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
34
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
35
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
36
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
37
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
38
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
39
 * DEALINGS IN THE SOFTWARE.
 
40
 *
 
41
 ****************************************************************************/
 
42
 
 
43
#include <evemu.h>
 
44
#include <stdio.h>
 
45
#include <fcntl.h>
 
46
#include <string.h>
 
47
#include <unistd.h>
 
48
 
 
49
static int describe_device(int fd)
 
50
{
 
51
        struct evemu_device *dev;
 
52
        int ret = -ENOMEM;
 
53
 
 
54
        dev = evemu_new(0);
 
55
        if (!dev)
 
56
                goto out;
 
57
        ret = evemu_extract(dev, fd);
 
58
        if (ret)
 
59
                goto out;
 
60
 
 
61
        evemu_write(dev, stdout);
 
62
out:
 
63
        evemu_delete(dev);
 
64
        return ret;
 
65
}
 
66
 
 
67
int main(int argc, char *argv[])
 
68
{
 
69
        int fd;
 
70
        if (argc < 2) {
 
71
                fprintf(stderr, "Usage: %s <device>\n", argv[0]);
 
72
                return -1;
 
73
        }
 
74
        fd = open(argv[1], O_RDONLY);
 
75
        if (fd < 0) {
 
76
                fprintf(stderr, "error: could not open device\n");
 
77
                return -1;
 
78
        }
 
79
        if (describe_device(fd)) {
 
80
                fprintf(stderr, "error: could not describe device\n");
 
81
        }
 
82
        close(fd);
 
83
        return 0;
 
84
}