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_class.c
struct sysfs_device*
    sysfs_get_classdev_device(struct sysfs_class_device* clsdev)
{
    char linkpath[SYSFS_PATH_MAX], devpath[SYSFS_PATH_MAX];

    if (!clsdev)
    {
        errno = EINVAL;
        return NULL;
    }

    if (clsdev->sysdevice)
        return clsdev->sysdevice;

    memset(linkpath, 0, SYSFS_PATH_MAX);
    safestrcpy(linkpath, clsdev->path);
    safestrcat(linkpath, "/device");
    if (!sysfs_path_is_link(linkpath))
    {
        memset(devpath, 0, SYSFS_PATH_MAX);
        if (!sysfs_get_link(linkpath, devpath, SYSFS_PATH_MAX))
            clsdev->sysdevice = sysfs_open_device_path(devpath);
    }
    return clsdev->sysdevice;
}
/**
 * sysfs_get_classdev_device: gets the sysfs_device associated with the
 * 	given sysfs_class_device
 * @clsdev: class device whose associated sysfs_device is needed
 * returns struct sysfs_device * on success or NULL on error
 */
gets the sysfs_device associated with the
given sysfs_class_device
@clsdev: class device whose associated sysfs_device is needed
returns struct sysfs_device * on success or NULL on error
gets the sysfs_device associated with the given sysfs_class_device @clsdev : class device whose associated sysfs_device is needed returns struct sysfs_device * on success or NULL on error
struct sysfs_device*
    sysfs_get_classdev_device(struct sysfs_class_device* clsdev)
{
    char linkpath[SYSFS_PATH_MAX], devpath[SYSFS_PATH_MAX];
    if (!clsdev)
    {
        errno = EINVAL;
        return NULL;
    }
    if (clsdev->sysdevice)
        return clsdev->sysdevice;
    memset(linkpath, 0, SYSFS_PATH_MAX);
    safestrcpy(linkpath, clsdev->path);
    safestrcat(linkpath, "/device");
    if (!sysfs_path_is_link(linkpath))
    {
        memset(devpath, 0, SYSFS_PATH_MAX);
        if (!sysfs_get_link(linkpath, devpath, SYSFS_PATH_MAX))
            clsdev->sysdevice = sysfs_open_device_path(devpath);
    }
    return clsdev->sysdevice;
}
struct sysfs_device * sysfs_get_classdev_device ( struct sysfs_class_device * clsdev ) { char linkpath [ SYSFS_PATH_MAX ] , devpath [ SYSFS_PATH_MAX ] ; if ( ! clsdev ) { errno = EINVAL ; return NULL ; } if ( clsdev -> sysdevice ) return clsdev -> sysdevice ; memset ( linkpath , 0 , SYSFS_PATH_MAX ) ; safestrcpy ( linkpath , clsdev -> path ) ; safestrcat ( linkpath , " " ) ; if ( ! sysfs_path_is_link ( linkpath ) ) { memset ( devpath , 0 , SYSFS_PATH_MAX ) ; if ( ! sysfs_get_link ( linkpath , devpath , SYSFS_PATH_MAX ) ) clsdev -> sysdevice = sysfs_open_device_path ( devpath ) ; } return clsdev -> sysdevice ; }
sysfs_get_classdev_device: gets the sysfs_device associated with the
      given sysfs_class_device
 @clsdev: class device whose associated sysfs_device is needed
 returns struct sysfs_device * on success or NULL on error
sysfs_get_classdev_device : gets the sysfs_device associated with the given sysfs_class_device @clsdev : class device whose associated sysfs_device is needed returns struct sysfs_device * on success or NULL on error