openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/sysfsutils/2.1.0-r5/sysfsutils-2.1.0/lib/sysfs_device.c
struct sysfs_device* sysfs_open_device_path(const char* path)
{
    struct sysfs_device* dev;

    if (!path)
    {
        errno = EINVAL;
        return NULL;
    }
    if (sysfs_path_is_dir(path))
    {
        dprintf("Incorrect path to device: %s\n", path);
        return NULL;
    }
    dev = alloc_device();
    if (!dev)
    {
        dprintf("Error allocating device at %s\n", path);
        return NULL;
    }
    if (sysfs_get_name_from_path(path, dev->bus_id, SYSFS_NAME_LEN))
    {
        errno = EINVAL;
        dprintf("Error getting device bus_id\n");
        sysfs_close_device(dev);
        return NULL;
    }
    safestrcpy(dev->path, path);
    if (sysfs_remove_trailing_slash(dev->path))
    {
        dprintf("Invalid path to device %s\n", dev->path);
        sysfs_close_device(dev);
        return NULL;
    }
    /*
     * The "name" attribute no longer exists... return the device's
     * sysfs representation instead, in the "dev->name" field, which
     * implies that the dev->name and dev->bus_id contain same data.
     */
    safestrcpy(dev->name, dev->bus_id);

    if (sysfs_get_device_bus(dev))
        dprintf("Could not get device bus\n");

    if (get_dev_driver(dev))
    {
        dprintf("Could not get device %s's driver\n", dev->bus_id);
        safestrcpy(dev->driver_name, SYSFS_UNKNOWN);
    }

    if (get_dev_subsystem(dev))
    {
        dprintf("Could not get device %s's subsystem\n", dev->bus_id);
        safestrcpy(dev->subsystem, SYSFS_UNKNOWN);
    }
    return dev;
}
/**
 * sysfs_open_device_path: opens and populates device structure
 * @path: path to device, this is the /sys/devices/ path
 * returns sysfs_device structure with success or NULL with error
 */
opens and populates device structure
@path: path to device, this is the /sys/devices/ path
returns sysfs_device structure with success or NULL with error
opens and populates device structure @path : path to device this is the / sys / devices / path returns sysfs_device structure with success or NULL with error
struct sysfs_device* sysfs_open_device_path(const char* path)
{
    struct sysfs_device* dev;
    if (!path)
    {
        errno = EINVAL;
        return NULL;
    }
    if (sysfs_path_is_dir(path))
    {
        dprintf("Incorrect path to device: %s\n", path);
        return NULL;
    }
    dev = alloc_device();
    if (!dev)
    {
        dprintf("Error allocating device at %s\n", path);
        return NULL;
    }
    if (sysfs_get_name_from_path(path, dev->bus_id, SYSFS_NAME_LEN))
    {
        errno = EINVAL;
        dprintf("Error getting device bus_id\n");
        sysfs_close_device(dev);
        return NULL;
    }
    safestrcpy(dev->path, path);
    if (sysfs_remove_trailing_slash(dev->path))
    {
        dprintf("Invalid path to device %s\n", dev->path);
        sysfs_close_device(dev);
        return NULL;
    }
    safestrcpy(dev->name, dev->bus_id);
    if (sysfs_get_device_bus(dev))
        dprintf("Could not get device bus\n");
    if (get_dev_driver(dev))
    {
        dprintf("Could not get device %s's driver\n", dev->bus_id);
        safestrcpy(dev->driver_name, SYSFS_UNKNOWN);
    }
    if (get_dev_subsystem(dev))
    {
        dprintf("Could not get device %s's subsystem\n", dev->bus_id);
        safestrcpy(dev->subsystem, SYSFS_UNKNOWN);
    }
    return dev;
}
struct sysfs_device * sysfs_open_device_path ( const char * path ) { struct sysfs_device * dev ; if ( ! path ) { errno = EINVAL ; return NULL ; } if ( sysfs_path_is_dir ( path ) ) { dprintf ( " \n " , path ) ; return NULL ; } dev = alloc_device ( ) ; if ( ! dev ) { dprintf ( " \n " , path ) ; return NULL ; } if ( sysfs_get_name_from_path ( path , dev -> bus_id , SYSFS_NAME_LEN ) ) { errno = EINVAL ; dprintf ( " \n " ) ; sysfs_close_device ( dev ) ; return NULL ; } safestrcpy ( dev -> path , path ) ; if ( sysfs_remove_trailing_slash ( dev -> path ) ) { dprintf ( " \n " , dev -> path ) ; sysfs_close_device ( dev ) ; return NULL ; } safestrcpy ( dev -> name , dev -> bus_id ) ; if ( sysfs_get_device_bus ( dev ) ) dprintf ( " \n " ) ; if ( get_dev_driver ( dev ) ) { dprintf ( " \n " , dev -> bus_id ) ; safestrcpy ( dev -> driver_name , SYSFS_UNKNOWN ) ; } if ( get_dev_subsystem ( dev ) ) { dprintf ( " \n " , dev -> bus_id ) ; safestrcpy ( dev -> subsystem , SYSFS_UNKNOWN ) ; } return dev ; }
sysfs_open_device_path: opens and populates device structure
 @path: path to device, this is the /sys/devices/ path
 returns sysfs_device structure with success or NULL with error
sysfs_open_device_path : opens and populates device structure @path : path to device this is the / sys / devices / path returns sysfs_device structure with success or NULL with error
/*
     * The "name" attribute no longer exists... return the device's
     * sysfs representation instead, in the "dev->name" field, which
     * implies that the dev->name and dev->bus_id contain same data.
     */