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_driver.c
struct sysfs_driver* sysfs_open_driver_path(const char* path)
{
    struct sysfs_driver* driver = NULL;

    if (!path)
    {
        errno = EINVAL;
        return NULL;
    }
    if (sysfs_path_is_dir(path))
    {
        dprintf("Invalid path to driver: %s\n", path);
        return NULL;
    }
    driver = alloc_driver();
    if (!driver)
    {
        dprintf("Error allocating driver at %s\n", path);
        return NULL;
    }
    if (sysfs_get_name_from_path(path, driver->name, SYSFS_NAME_LEN))
    {
        dprintf("Error getting driver name from path\n");
        free(driver);
        return NULL;
    }
    safestrcpy(driver->path, path);
    if (sysfs_remove_trailing_slash(driver->path))
    {
        dprintf("Invalid path to driver %s\n", driver->path);
        sysfs_close_driver(driver);
        return NULL;
    }
    if (get_driver_bus(driver))
    {
        dprintf("Could not get the bus driver is on\n");
        sysfs_close_driver(driver);
        return NULL;
    }

    return driver;
}
/**
 * sysfs_open_driver_path: opens and initializes driver structure
 * @path: path to driver directory
 * returns struct sysfs_driver with success and NULL with error
 */
opens and initializes driver structure
@path: path to driver directory
returns struct sysfs_driver with success and NULL with error
opens and initializes driver structure @path : path to driver directory returns struct sysfs_driver with success and NULL with error
struct sysfs_driver* sysfs_open_driver_path(const char* path)
{
    struct sysfs_driver* driver = NULL;
    if (!path)
    {
        errno = EINVAL;
        return NULL;
    }
    if (sysfs_path_is_dir(path))
    {
        dprintf("Invalid path to driver: %s\n", path);
        return NULL;
    }
    driver = alloc_driver();
    if (!driver)
    {
        dprintf("Error allocating driver at %s\n", path);
        return NULL;
    }
    if (sysfs_get_name_from_path(path, driver->name, SYSFS_NAME_LEN))
    {
        dprintf("Error getting driver name from path\n");
        free(driver);
        return NULL;
    }
    safestrcpy(driver->path, path);
    if (sysfs_remove_trailing_slash(driver->path))
    {
        dprintf("Invalid path to driver %s\n", driver->path);
        sysfs_close_driver(driver);
        return NULL;
    }
    if (get_driver_bus(driver))
    {
        dprintf("Could not get the bus driver is on\n");
        sysfs_close_driver(driver);
        return NULL;
    }
    return driver;
}
struct sysfs_driver * sysfs_open_driver_path ( const char * path ) { struct sysfs_driver * driver = NULL ; if ( ! path ) { errno = EINVAL ; return NULL ; } if ( sysfs_path_is_dir ( path ) ) { dprintf ( " \n " , path ) ; return NULL ; } driver = alloc_driver ( ) ; if ( ! driver ) { dprintf ( " \n " , path ) ; return NULL ; } if ( sysfs_get_name_from_path ( path , driver -> name , SYSFS_NAME_LEN ) ) { dprintf ( " \n " ) ; free ( driver ) ; return NULL ; } safestrcpy ( driver -> path , path ) ; if ( sysfs_remove_trailing_slash ( driver -> path ) ) { dprintf ( " \n " , driver -> path ) ; sysfs_close_driver ( driver ) ; return NULL ; } if ( get_driver_bus ( driver ) ) { dprintf ( " \n " ) ; sysfs_close_driver ( driver ) ; return NULL ; } return driver ; }
sysfs_open_driver_path: opens and initializes driver structure
 @path: path to driver directory
 returns struct sysfs_driver with success and NULL with error
sysfs_open_driver_path : opens and initializes driver structure @path : path to driver directory returns struct sysfs_driver with success and NULL with error