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_get_class_device(struct sysfs_class* cls,
                                                  const char* name)
{
    char path[SYSFS_PATH_MAX];
    struct sysfs_class_device* cdev = NULL;

    if (!cls || !name)
    {
        errno = EINVAL;
        return NULL;
    }

    if (cls->devices)
    {
        cdev = (struct sysfs_class_device*)dlist_find_custom(
            cls->devices, (void*)name, cdev_name_equal);
        if (cdev)
            return cdev;
    }

    safestrcpy(path, cls->path);
    safestrcat(path, "/");
    safestrcat(path, name);
    cdev = sysfs_open_class_device_path(path);
    if (!cdev)
    {
        dprintf("Error opening class device at %s\n", path);
        return NULL;
    }
    if (!cls->devices)
        cls->devices = dlist_new_with_delete(sizeof(struct sysfs_class_device),
                                             sysfs_close_cls_dev);

    dlist_unshift_sorted(cls->devices, cdev, sort_list);
    return cdev;
}
/**
 * sysfs_get_class_device: get specific class device using the device's id
 * @cls: sysfs_class to find the device on
 * @name: name of the class device to look for
 *
 * Returns sysfs_class_device * on success and NULL on failure
 */
get specific class device using the device's id
@cls: sysfs_class to find the device on
@name: name of the class device to look for

Returns sysfs_class_device * on success and NULL on failure
get specific class device using the device ' s id @cls : sysfs_class to find the device on @name : name of the class device to look for Returns sysfs_class_device * on success and NULL on failure
struct sysfs_class_device* sysfs_get_class_device(struct sysfs_class* cls,
                                                  const char* name)
{
    char path[SYSFS_PATH_MAX];
    struct sysfs_class_device* cdev = NULL;
    if (!cls || !name)
    {
        errno = EINVAL;
        return NULL;
    }
    if (cls->devices)
    {
        cdev = (struct sysfs_class_device*)dlist_find_custom(
            cls->devices, (void*)name, cdev_name_equal);
        if (cdev)
            return cdev;
    }
    safestrcpy(path, cls->path);
    safestrcat(path, "/");
    safestrcat(path, name);
    cdev = sysfs_open_class_device_path(path);
    if (!cdev)
    {
        dprintf("Error opening class device at %s\n", path);
        return NULL;
    }
    if (!cls->devices)
        cls->devices = dlist_new_with_delete(sizeof(struct sysfs_class_device),
                                             sysfs_close_cls_dev);
    dlist_unshift_sorted(cls->devices, cdev, sort_list);
    return cdev;
}
struct sysfs_class_device * sysfs_get_class_device ( struct sysfs_class * cls , const char * name ) { char path [ SYSFS_PATH_MAX ] ; struct sysfs_class_device * cdev = NULL ; if ( ! cls || ! name ) { errno = EINVAL ; return NULL ; } if ( cls -> devices ) { cdev = ( struct sysfs_class_device * ) dlist_find_custom ( cls -> devices , ( void * ) name , cdev_name_equal ) ; if ( cdev ) return cdev ; } safestrcpy ( path , cls -> path ) ; safestrcat ( path , " " ) ; safestrcat ( path , name ) ; cdev = sysfs_open_class_device_path ( path ) ; if ( ! cdev ) { dprintf ( " \n " , path ) ; return NULL ; } if ( ! cls -> devices ) cls -> devices = dlist_new_with_delete ( sizeof ( struct sysfs_class_device ) , sysfs_close_cls_dev ) ; dlist_unshift_sorted ( cls -> devices , cdev , sort_list ) ; return cdev ; }
sysfs_get_class_device: get specific class device using the device's id
 @cls: sysfs_class to find the device on
 @name: name of the class device to look for
sysfs_get_class_device : get specific class device using the device ' s id @cls : sysfs_class to find the device on @name : name of the class device to look for