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_classdev_parent(struct sysfs_class_device* clsdev)
{
    char abs_path[SYSFS_PATH_MAX], tmp_path[SYSFS_PATH_MAX];
    char* c;

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

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

    memset(abs_path, 0, SYSFS_PATH_MAX);
    memset(tmp_path, 0, SYSFS_PATH_MAX);

    safestrcpy(tmp_path, clsdev->path);
    c = strstr(tmp_path, clsdev->classname);
    c = strchr(c, '/');
    *c = '\0';

    safestrcpy(abs_path, clsdev->path);
    c = strrchr(abs_path, '/');
    *c = '\0';

    if ((strncmp(tmp_path, abs_path, strlen(abs_path))) == 0)
    {
        dprintf("Class device %s doesn't have a parent\n", clsdev->name);
        return NULL;
    }

    clsdev->parent = sysfs_open_class_device_path(abs_path);

    return clsdev->parent;
}
/**
 * sysfs_get_classdev_parent: Retrieves the parent of a class device.
 * 	eg., when working with hda1, this function can be used to retrieve the
 * 		sysfs_class_device for hda
 *
 * @clsdev: class device whose parent details are required.
 * Returns sysfs_class_device of the parent on success, NULL on failure
 */
Retrieves the parent of a class device.
eg., when working with hda1, this function can be used to retrieve the
sysfs_class_device for hda

@clsdev: class device whose parent details are required.
Returns sysfs_class_device of the parent on success, NULL on failure
Retrieves the parent of a class device . eg . when working with hda1 this function can be used to retrieve the sysfs_class_device for hda @clsdev : class device whose parent details are required . Returns sysfs_class_device of the parent on success NULL on failure
struct sysfs_class_device*
    sysfs_get_classdev_parent(struct sysfs_class_device* clsdev)
{
    char abs_path[SYSFS_PATH_MAX], tmp_path[SYSFS_PATH_MAX];
    char* c;
    if (!clsdev)
    {
        errno = EINVAL;
        return NULL;
    }
    if (clsdev->parent)
        return (clsdev->parent);
    memset(abs_path, 0, SYSFS_PATH_MAX);
    memset(tmp_path, 0, SYSFS_PATH_MAX);
    safestrcpy(tmp_path, clsdev->path);
    c = strstr(tmp_path, clsdev->classname);
    c = strchr(c, '/');
    *c = '\0';
    safestrcpy(abs_path, clsdev->path);
    c = strrchr(abs_path, '/');
    *c = '\0';
    if ((strncmp(tmp_path, abs_path, strlen(abs_path))) == 0)
    {
        dprintf("Class device %s doesn't have a parent\n", clsdev->name);
        return NULL;
    }
    clsdev->parent = sysfs_open_class_device_path(abs_path);
    return clsdev->parent;
}
struct sysfs_class_device * sysfs_get_classdev_parent ( struct sysfs_class_device * clsdev ) { char abs_path [ SYSFS_PATH_MAX ] , tmp_path [ SYSFS_PATH_MAX ] ; char * c ; if ( ! clsdev ) { errno = EINVAL ; return NULL ; } if ( clsdev -> parent ) return ( clsdev -> parent ) ; memset ( abs_path , 0 , SYSFS_PATH_MAX ) ; memset ( tmp_path , 0 , SYSFS_PATH_MAX ) ; safestrcpy ( tmp_path , clsdev -> path ) ; c = strstr ( tmp_path , clsdev -> classname ) ; c = strchr ( c , ' ' ) ; * c = ' \0 ' ; safestrcpy ( abs_path , clsdev -> path ) ; c = strrchr ( abs_path , ' ' ) ; * c = ' \0 ' ; if ( ( strncmp ( tmp_path , abs_path , strlen ( abs_path ) ) ) == 0 ) { dprintf ( " \n " , clsdev -> name ) ; return NULL ; } clsdev -> parent = sysfs_open_class_device_path ( abs_path ) ; return clsdev -> parent ; }
sysfs_get_classdev_parent: Retrieves the parent of a class device.
sysfs_get_classdev_parent : Retrieves the parent of a class device .