usb-db.c revision ccba91c746dfbb5623d537f39842c6873607db96
/*-*- linux-c -*-*/
/*
* Copyright (C) 2009 Lennart Poettering <lennart@poettering.net>
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details:
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdlib.h>
#include <libudev.h>
#if defined(BUILD_FOR_USB)
# define DATABASE USB_DATABASE
# define SUBSYSTEM "usb"
# define DEVTYPE "usb_device"
# define VENDOR_ATTR "idVendor"
# define PRODUCT_ATTR "idProduct"
#elif defined(BUILD_FOR_PCI)
# define DATABASE PCI_DATABASE
# define SUBSYSTEM "pci"
# define VENDOR_ATTR "vendor"
# define PRODUCT_ATTR "device"
#else
# error "Are you havin' a laugh?"
#endif
static int get_id_attr(
struct udev_device *parent,
const char *name,
const char *t;
unsigned u;
return -1;
}
t += 2;
return -1;
}
return 0;
}
static int get_vid_pid(
struct udev_device *parent,
return -1;
else if (*vid <= 0) {
return -1;
}
return -1;
return 0;
}
static void rstrip(char *n) {
size_t i;
n[i-1] = 0;
}
#define HEXCHARS "0123456789abcdefABCDEF"
#define WHITESPACE " \t\n\r"
static int lookup_vid_pid(
char **vendor,
char **product) {
FILE *f;
int ret = -1;
int found_vendor = 0;
return -1;
}
for (;;) {
size_t n;
if (line) {
}
break;
continue;
unsigned u;
if (found_vendor)
break;
char *t;
t = line+4;
t += strspn(t, WHITESPACE);
goto finish;
}
found_vendor = 1;
}
continue;
}
unsigned u;
char *t;
t = line+5;
t += strspn(t, WHITESPACE);
goto finish;
}
break;
}
}
}
ret = 0;
fclose(f);
if (ret < 0) {
}
return ret;
}
static struct udev_device *find_device(struct udev_device *dev, const char *subsys, const char *devtype)
{
const char *str;
goto try_parent;
goto try_parent;
goto try_parent;
goto try_parent;
}
return dev;
}
int ret = 1;
char *sp;
if (argc < 2) {
goto finish;
}
goto finish;
goto finish;
}
if (!dev) {
goto finish;
}
if (!parent) {
goto finish;
}
goto finish;
goto finish;
if (vendor)
if (product)
ret = 0;
return ret;
}