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* sysfs_open_class(const char* name)
{
    struct sysfs_class* cls = NULL;
    char *c, classpath[SYSFS_PATH_MAX];

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

    memset(classpath, 0, SYSFS_PATH_MAX);
    if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0)
    {
        dprintf("Sysfs not supported on this system\n");
        return NULL;
    }

    safestrcat(classpath, "/");
    if (strcmp(name, SYSFS_BLOCK_NAME) == 0)
    {
        safestrcat(classpath, SYSFS_BLOCK_NAME);
        if (!sysfs_path_is_dir(classpath))
            goto done;
        c = strrchr(classpath, '/');
        *(c + 1) = '\0';
    }
    safestrcat(classpath, SYSFS_CLASS_NAME);
    safestrcat(classpath, "/");
    safestrcat(classpath, name);
done:
    if (sysfs_path_is_dir(classpath))
    {
        dprintf("Class %s not found on the system\n", name);
        return NULL;
    }

    cls = alloc_class();
    if (cls == NULL)
    {
        dprintf("calloc failed\n");
        return NULL;
    }
    safestrcpy(cls->name, name);
    safestrcpy(cls->path, classpath);
    if ((sysfs_remove_trailing_slash(cls->path)) != 0)
    {
        dprintf("Invalid path to class device %s\n", cls->path);
        sysfs_close_class(cls);
        return NULL;
    }

    return cls;
}
/**
 * sysfs_open_class: opens specific class and all its devices on system
 * returns sysfs_class structure with success or NULL with error.
 */
opens specific class and all its devices on system
returns sysfs_class structure with success or NULL with error.
opens specific class and all its devices on system returns sysfs_class structure with success or NULL with error .
struct sysfs_class* sysfs_open_class(const char* name)
{
    struct sysfs_class* cls = NULL;
    char *c, classpath[SYSFS_PATH_MAX];
    if (!name)
    {
        errno = EINVAL;
        return NULL;
    }
    memset(classpath, 0, SYSFS_PATH_MAX);
    if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0)
    {
        dprintf("Sysfs not supported on this system\n");
        return NULL;
    }
    safestrcat(classpath, "/");
    if (strcmp(name, SYSFS_BLOCK_NAME) == 0)
    {
        safestrcat(classpath, SYSFS_BLOCK_NAME);
        if (!sysfs_path_is_dir(classpath))
            goto done;
        c = strrchr(classpath, '/');
        *(c + 1) = '\0';
    }
    safestrcat(classpath, SYSFS_CLASS_NAME);
    safestrcat(classpath, "/");
    safestrcat(classpath, name);
done:
    if (sysfs_path_is_dir(classpath))
    {
        dprintf("Class %s not found on the system\n", name);
        return NULL;
    }
    cls = alloc_class();
    if (cls == NULL)
    {
        dprintf("calloc failed\n");
        return NULL;
    }
    safestrcpy(cls->name, name);
    safestrcpy(cls->path, classpath);
    if ((sysfs_remove_trailing_slash(cls->path)) != 0)
    {
        dprintf("Invalid path to class device %s\n", cls->path);
        sysfs_close_class(cls);
        return NULL;
    }
    return cls;
}
struct sysfs_class * sysfs_open_class ( const char * name ) { struct sysfs_class * cls = NULL ; char * c , classpath [ SYSFS_PATH_MAX ] ; if ( ! name ) { errno = EINVAL ; return NULL ; } memset ( classpath , 0 , SYSFS_PATH_MAX ) ; if ( ( sysfs_get_mnt_path ( classpath , SYSFS_PATH_MAX ) ) != 0 ) { dprintf ( " \n " ) ; return NULL ; } safestrcat ( classpath , " " ) ; if ( strcmp ( name , SYSFS_BLOCK_NAME ) == 0 ) { safestrcat ( classpath , SYSFS_BLOCK_NAME ) ; if ( ! sysfs_path_is_dir ( classpath ) ) goto done ; c = strrchr ( classpath , ' ' ) ; * ( c + 1 ) = ' \0 ' ; } safestrcat ( classpath , SYSFS_CLASS_NAME ) ; safestrcat ( classpath , " " ) ; safestrcat ( classpath , name ) ; done : if ( sysfs_path_is_dir ( classpath ) ) { dprintf ( " \n " , name ) ; return NULL ; } cls = alloc_class ( ) ; if ( cls == NULL ) { dprintf ( " \n " ) ; return NULL ; } safestrcpy ( cls -> name , name ) ; safestrcpy ( cls -> path , classpath ) ; if ( ( sysfs_remove_trailing_slash ( cls -> path ) ) != 0 ) { dprintf ( " \n " , cls -> path ) ; sysfs_close_class ( cls ) ; return NULL ; } return cls ; }
sysfs_open_class: opens specific class and all its devices on system
 returns sysfs_class structure with success or NULL with error.
sysfs_open_class : opens specific class and all its devices on system returns sysfs_class structure with success or NULL with error .