openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/mtd-utils/2.1.0+AUTOINC+b5027be5f4-r0/git/ubifs-utils/mkfs.ubifs/devtable.c
static int separate_last(const char* buf, int len, char** path, char** name)
{
    int path_len = len, name_len;
    const char *p = buf + len, *n;

    while (*--p != '/')
        path_len -= 1;

    /* Drop the final '/' unless this is the root directory */
    name_len = len - path_len;
    n = buf + path_len;
    if (path_len > 1)
        path_len -= 1;

    *path = malloc(path_len + 1);
    if (!*path)
        return err_msg("cannot allocate %d bytes of memory", path_len + 1);
    memcpy(*path, buf, path_len);
    (*path)[path_len] = '\0';

    *name = malloc(name_len + 1);
    if (!*name)
    {
        free(*path);
        return err_msg("cannot allocate %d bytes of memory", name_len + 1);
    }
    memcpy(*name, n, name_len + 1);

    return 0;
}
/**
 * separate_last - separate out the last path component
 * @buf: the path to split
 * @len: length of the @buf string
 * @path: the beginning of path is returned here
 * @name: the last path component is returned here
 *
 * This helper function separates out the the last component of the full path
 * string. For example, "/dev/loop" would be split on "/dev" and "loop". This
 * function allocates memory for @path and @name and return the result there.
 * Returns zero in case of success and a negative error code in case of
 * failure.
 */


This helper function separates out the the last component of the full path
string.
This helper function separates out the the last component of the full path string .
static int separate_last(const char* buf, int len, char** path, char** name)
{
    int path_len = len, name_len;
    const char *p = buf + len, *n;
    while (*--p != '/')
        path_len -= 1;
    name_len = len - path_len;
    n = buf + path_len;
    if (path_len > 1)
        path_len -= 1;
    *path = malloc(path_len + 1);
    if (!*path)
        return err_msg("cannot allocate %d bytes of memory", path_len + 1);
    memcpy(*path, buf, path_len);
    (*path)[path_len] = '\0';
    *name = malloc(name_len + 1);
    if (!*name)
    {
        free(*path);
        return err_msg("cannot allocate %d bytes of memory", name_len + 1);
    }
    memcpy(*name, n, name_len + 1);
    return 0;
}
static int separate_last ( const char * buf , int len , char * * path , char * * name ) { int path_len = len , name_len ; const char * p = buf + len , * n ; while ( * -- p != ' ' ) path_len -= 1 ; name_len = len - path_len ; n = buf + path_len ; if ( path_len > 1 ) path_len -= 1 ; * path = malloc ( path_len + 1 ) ; if ( ! * path ) return err_msg ( " " , path_len + 1 ) ; memcpy ( * path , buf , path_len ) ; ( * path ) [ path_len ] = ' \0 ' ; * name = malloc ( name_len + 1 ) ; if ( ! * name ) { free ( * path ) ; return err_msg ( " " , name_len + 1 ) ; } memcpy ( * name , n , name_len + 1 ) ; return 0 ; }
separate_last - separate out the last path component
 @buf: the path to split
 @len: length of the @buf string
 @path: the beginning of path is returned here
 @name: the last path component is returned here
separate_last - separate out the last path component @buf : the path to split @len : length of the @buf string @path : the beginning of path is returned here @name : the last path component is returned here
/* Drop the final '/' unless this is the root directory */