static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name,

                                  unsigned int *pvalue, int base)

{

    char path[PATH_MAX];

    char buf[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE];

    int fd, rc;

    unsigned long value;

    char *endptr;



    xen_host_pci_sysfs_path(d, name, path, sizeof(path));



    fd = open(path, O_RDONLY);

    if (fd == -1) {

        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));

        return -errno;

    }

    do {

        rc = read(fd, &buf, sizeof (buf) - 1);

        if (rc < 0 && errno != EINTR) {

            rc = -errno;

            goto out;

        }

    } while (rc < 0);

    buf[rc] = 0;

    value = strtol(buf, &endptr, base);

    if (endptr == buf || *endptr != '\n') {

        rc = -1;

    } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) {

        rc = -errno;

    } else {

        rc = 0;

        *pvalue = value;

    }

out:

    close(fd);

    return rc;

}

static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name,

                                  unsigned int *pvalue, int base)

{

    char path[PATH_MAX];

    char buf[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE];

    int fd, rc;

    unsigned long value;

    char *endptr;



    xen_host_pci_sysfs_path(d, name, path, sizeof(path));



    fd = open(path, O_RDONLY);

    if (fd == -1) {

        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));

        return -errno;

    }

    do {

        rc = read(fd, &buf, sizeof (buf) - 1);

        if (rc < 0 && errno != EINTR) {

            rc = -errno;

            goto out;

        }

    } while (rc < 0);

    buf[rc] = 0;

    value = strtol(buf, &endptr, base);

    if (endptr == buf || *endptr != '\n') {

        rc = -1;

    } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) {

        rc = -errno;

    } else {

        rc = 0;

        *pvalue = value;

    }

out:

    close(fd);

    return rc;

}

static int FUNC_0(XenHostPCIDevice *VAR_0, const char *VAR_1,

                                  unsigned int *VAR_2, int VAR_3)

{

    char VAR_4[PATH_MAX];

    char VAR_5[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE];

    int VAR_6, VAR_7;

    unsigned long VAR_8;

    char *VAR_9;



    xen_host_pci_sysfs_path(VAR_0, VAR_1, VAR_4, sizeof(VAR_4));



    VAR_6 = open(VAR_4, O_RDONLY);

    if (VAR_6 == -1) {

        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", VAR_4, strerror(errno));

        return -errno;

    }

    do {

        VAR_7 = read(VAR_6, &VAR_5, sizeof (VAR_5) - 1);

        if (VAR_7 < 0 && errno != EINTR) {

            VAR_7 = -errno;

            goto out;

        }

    } while (VAR_7 < 0);

    VAR_5[VAR_7] = 0;

    VAR_8 = strtol(VAR_5, &VAR_9, VAR_3);

    if (VAR_9 == VAR_5 || *VAR_9 != '\n') {

        VAR_7 = -1;

    } else if ((VAR_8 == LONG_MIN || VAR_8 == LONG_MAX) && errno == ERANGE) {

        VAR_7 = -errno;

    } else {

        VAR_7 = 0;

        *VAR_2 = VAR_8;

    }

out:

    close(VAR_6);

    return VAR_7;

}

static int FUNC_0(XenHostPCIDevice *VAR_0, const char *VAR_1,
unsigned int *VAR_2, int VAR_3)
{ char VAR_4[PATH_MAX]; char VAR_5[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE]; int VAR_6, VAR_7; unsigned long VAR_8; char *VAR_9; xen_host_pci_sysfs_path(VAR_0, VAR_1, VAR_4, sizeof(VAR_4)); VAR_6 = open(VAR_4, O_RDONLY); if (VAR_6 == -1) { XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", VAR_4, strerror(errno)); return -errno; } do { VAR_7 = read(VAR_6, &VAR_5, sizeof (VAR_5) - 1); if (VAR_7 < 0 && errno != EINTR) { VAR_7 = -errno; goto out; } } while (VAR_7 < 0); VAR_5[VAR_7] = 0; VAR_8 = strtol(VAR_5, &VAR_9, VAR_3); if (VAR_9 == VAR_5 || *VAR_9 != '\n') { VAR_7 = -1; } else if ((VAR_8 == LONG_MIN || VAR_8 == LONG_MAX) && errno == ERANGE) { VAR_7 = -errno; } else { VAR_7 = 0; *VAR_2 = VAR_8; } out:
close(VAR_6); return VAR_7; }