openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/lib/canonicalize.c
char* absolute_path(const char* path)
{
    char cwd[PATH_MAX], *res, *p;
    size_t psz, csz;

    if (!is_relative_path(path))
    {
        errno = EINVAL;
        return NULL;
    }
    if (!getcwd(cwd, sizeof(cwd)))
        return NULL;

    /* simple clean up */
    if (startswith(path, "./"))
        path += 2;
    else if (strcmp(path, ".") == 0)
        path = NULL;

    if (!path || !*path)
        return strdup(cwd);

    csz = strlen(cwd);
    psz = strlen(path);

    p = res = malloc(csz + 1 + psz + 1);
    if (!res)
        return NULL;

    memcpy(p, cwd, csz);
    p += csz;
    *p++ = '/';
    memcpy(p, path, psz + 1);

    return res;
}
/*
 * This function does not canonicalize the path! It just prepends CWD before a
 * relative path. If the path is no relative than returns NULL. The path does
 * not have to exist.
 */
This function does not canonicalize the path. It just prepends CWD before a
relative path. If the path is no relative than returns NULL. The path does
not have to exist.
This function does not canonicalize the path . It just prepends CWD before a relative path . If the path is no relative than returns NULL . The path does not have to exist .
char* absolute_path(const char* path)
{
    char cwd[PATH_MAX], *res, *p;
    size_t psz, csz;
    if (!is_relative_path(path))
    {
        errno = EINVAL;
        return NULL;
    }
    if (!getcwd(cwd, sizeof(cwd)))
        return NULL;
    if (startswith(path, "./"))
        path += 2;
    else if (strcmp(path, ".") == 0)
        path = NULL;
    if (!path || !*path)
        return strdup(cwd);
    csz = strlen(cwd);
    psz = strlen(path);
    p = res = malloc(csz + 1 + psz + 1);
    if (!res)
        return NULL;
    memcpy(p, cwd, csz);
    p += csz;
    *p++ = '/';
    memcpy(p, path, psz + 1);
    return res;
}
char * absolute_path ( const char * path ) { char cwd [ PATH_MAX ] , * res , * p ; size_t psz , csz ; if ( ! is_relative_path ( path ) ) { errno = EINVAL ; return NULL ; } if ( ! getcwd ( cwd , sizeof ( cwd ) ) ) return NULL ; if ( startswith ( path , " " ) ) path += 2 ; else if ( strcmp ( path , " " ) == 0 ) path = NULL ; if ( ! path || ! * path ) return strdup ( cwd ) ; csz = strlen ( cwd ) ; psz = strlen ( path ) ; p = res = malloc ( csz + 1 + psz + 1 ) ; if ( ! res ) return NULL ; memcpy ( p , cwd , csz ) ; p += csz ; * p ++ = ' ' ; memcpy ( p , path , psz + 1 ) ; return res ; }
This function does not canonicalize the path!
This function does not canonicalize the path!
/* simple clean up */