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
int sysfs_get_device_bus(struct sysfs_device* dev)
{
    char devpath[SYSFS_PATH_MAX], path[SYSFS_PATH_MAX];

    if (!dev)
    {
        errno = EINVAL;
        return -1;
    }

    memset(path, 0, SYSFS_PATH_MAX);
    memset(devpath, 0, SYSFS_PATH_MAX);
    safestrcpymax(path, dev->path, SYSFS_PATH_MAX);
    safestrcatmax(path, "/bus", SYSFS_PATH_MAX);
    if (!sysfs_path_is_link(path))
    {
        if (!sysfs_get_link(path, devpath, SYSFS_PATH_MAX))
        {
            if (!sysfs_get_name_from_path(devpath, dev->bus, SYSFS_NAME_LEN))
                return 0;
        }
    }
    return -1;
}
/**
 * sysfs_get_device_bus: retrieves the bus name the device is on, checks path
 * 	to bus' link to make sure it has correct device.
 * @dev: device to get busname.
 * returns 0 with success and -1 with error.
 */
retrieves the bus name the device is on, checks path
to bus' link to make sure it has correct device.
@dev: device to get busname.
returns 0 with success and -1 with error.
retrieves the bus name the device is on checks path to bus ' link to make sure it has correct device . @dev : device to get busname . returns 0 with success and - 1 with error .
int sysfs_get_device_bus(struct sysfs_device* dev)
{
    char devpath[SYSFS_PATH_MAX], path[SYSFS_PATH_MAX];
    if (!dev)
    {
        errno = EINVAL;
        return -1;
    }
    memset(path, 0, SYSFS_PATH_MAX);
    memset(devpath, 0, SYSFS_PATH_MAX);
    safestrcpymax(path, dev->path, SYSFS_PATH_MAX);
    safestrcatmax(path, "/bus", SYSFS_PATH_MAX);
    if (!sysfs_path_is_link(path))
    {
        if (!sysfs_get_link(path, devpath, SYSFS_PATH_MAX))
        {
            if (!sysfs_get_name_from_path(devpath, dev->bus, SYSFS_NAME_LEN))
                return 0;
        }
    }
    return -1;
}
int sysfs_get_device_bus ( struct sysfs_device * dev ) { char devpath [ SYSFS_PATH_MAX ] , path [ SYSFS_PATH_MAX ] ; if ( ! dev ) { errno = EINVAL ; return -1 ; } memset ( path , 0 , SYSFS_PATH_MAX ) ; memset ( devpath , 0 , SYSFS_PATH_MAX ) ; safestrcpymax ( path , dev -> path , SYSFS_PATH_MAX ) ; safestrcatmax ( path , " " , SYSFS_PATH_MAX ) ; if ( ! sysfs_path_is_link ( path ) ) { if ( ! sysfs_get_link ( path , devpath , SYSFS_PATH_MAX ) ) { if ( ! sysfs_get_name_from_path ( devpath , dev -> bus , SYSFS_NAME_LEN ) ) return 0 ; } } return -1 ; }
sysfs_get_device_bus: retrieves the bus name the device is on, checks path
      to bus' link to make sure it has correct device.
sysfs_get_device_bus : retrieves the bus name the device is on checks path to bus ' link to make sure it has correct device .