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_class_device* sysfs_open_class_device_path(const char* path)
{
    struct sysfs_class_device* cdev;
    char temp_path[SYSFS_PATH_MAX];

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

    /*
     * Post linux-2.6.14 driver model supports nested classes with
     * links to the nested hierarchy at /sys/class/xxx/. Check for
     * a link to the actual class device if a directory isn't found
     */
    if (sysfs_path_is_dir(path))
    {
        dprintf("%s: Directory not found, checking for a link\n", path);
        if (!sysfs_path_is_link(path))
        {
            if (sysfs_get_link(path, temp_path, SYSFS_PATH_MAX))
            {
                dprintf("Error retrieving link at %s\n", path);
                return NULL;
            }
        }
        else
        {
            dprintf("%s is not a valid class device path\n", path);
            return NULL;
        }
    }
    else
        safestrcpy(temp_path, path);

    cdev = alloc_class_device();
    if (!cdev)
    {
        dprintf("calloc failed\n");
        return NULL;
    }
    if (sysfs_get_name_from_path(temp_path, cdev->name, SYSFS_NAME_LEN))
    {
        errno = EINVAL;
        dprintf("Error getting class device name\n");
        sysfs_close_class_device(cdev);
        return NULL;
    }

    safestrcpy(cdev->path, temp_path);
    if (sysfs_remove_trailing_slash(cdev->path))
    {
        dprintf("Invalid path to class device %s\n", cdev->path);
        sysfs_close_class_device(cdev);
        return NULL;
    }
    set_classdev_classname(cdev);

    return cdev;
}
/**
 * sysfs_open_class_device_path: Opens and populates class device
 * @path: path to class device.
 * returns struct sysfs_class_device with success and NULL with error.
 */
Opens and populates class device
@path: path to class device.
returns struct sysfs_class_device with success and NULL with error.
Opens and populates class device @path : path to class device . returns struct sysfs_class_device with success and NULL with error .
struct sysfs_class_device* sysfs_open_class_device_path(const char* path)
{
    struct sysfs_class_device* cdev;
    char temp_path[SYSFS_PATH_MAX];
    if (!path)
    {
        errno = EINVAL;
        return NULL;
    }
    if (sysfs_path_is_dir(path))
    {
        dprintf("%s: Directory not found, checking for a link\n", path);
        if (!sysfs_path_is_link(path))
        {
            if (sysfs_get_link(path, temp_path, SYSFS_PATH_MAX))
            {
                dprintf("Error retrieving link at %s\n", path);
                return NULL;
            }
        }
        else
        {
            dprintf("%s is not a valid class device path\n", path);
            return NULL;
        }
    }
    else
        safestrcpy(temp_path, path);
    cdev = alloc_class_device();
    if (!cdev)
    {
        dprintf("calloc failed\n");
        return NULL;
    }
    if (sysfs_get_name_from_path(temp_path, cdev->name, SYSFS_NAME_LEN))
    {
        errno = EINVAL;
        dprintf("Error getting class device name\n");
        sysfs_close_class_device(cdev);
        return NULL;
    }
    safestrcpy(cdev->path, temp_path);
    if (sysfs_remove_trailing_slash(cdev->path))
    {
        dprintf("Invalid path to class device %s\n", cdev->path);
        sysfs_close_class_device(cdev);
        return NULL;
    }
    set_classdev_classname(cdev);
    return cdev;
}
struct sysfs_class_device * sysfs_open_class_device_path ( const char * path ) { struct sysfs_class_device * cdev ; char temp_path [ SYSFS_PATH_MAX ] ; if ( ! path ) { errno = EINVAL ; return NULL ; } if ( sysfs_path_is_dir ( path ) ) { dprintf ( " \n " , path ) ; if ( ! sysfs_path_is_link ( path ) ) { if ( sysfs_get_link ( path , temp_path , SYSFS_PATH_MAX ) ) { dprintf ( " \n " , path ) ; return NULL ; } } else { dprintf ( " \n " , path ) ; return NULL ; } } else safestrcpy ( temp_path , path ) ; cdev = alloc_class_device ( ) ; if ( ! cdev ) { dprintf ( " \n " ) ; return NULL ; } if ( sysfs_get_name_from_path ( temp_path , cdev -> name , SYSFS_NAME_LEN ) ) { errno = EINVAL ; dprintf ( " \n " ) ; sysfs_close_class_device ( cdev ) ; return NULL ; } safestrcpy ( cdev -> path , temp_path ) ; if ( sysfs_remove_trailing_slash ( cdev -> path ) ) { dprintf ( " \n " , cdev -> path ) ; sysfs_close_class_device ( cdev ) ; return NULL ; } set_classdev_classname ( cdev ) ; return cdev ; }
sysfs_open_class_device_path: Opens and populates class device
 @path: path to class device.
sysfs_open_class_device_path : Opens and populates class device @path : path to class device .
/*
     * Post linux-2.6.14 driver model supports nested classes with
     * links to the nested hierarchy at /sys/class/xxx/. Check for
     * a link to the actual class device if a directory isn't found
     */