Changeset 3768


Ignore:
Timestamp:
Mar 15, 2012, 8:59:12 PM (13 years ago)
Author:
bird
Message:

realpath and _realrealpath should not fail if the last component does not exist. Extending lib_Back_fsPathResolve with a flag to this effect.

Location:
trunk/libc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/include/klibc/backend.h

    r3688 r3768  
    258258/** Flags for __libc_Back_fsPathResolve().
    259259 * @{ */
    260 #define __LIBC_BACKFS_FLAGS_RESOLVE_FULL    0
     260#define __LIBC_BACKFS_FLAGS_RESOLVE_FULL        0
     261/** Resolves and verfies the entire path, but it's ok if the last component
     262 * does not exist. */
     263#define __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE  0x01
    261264/** Get the native path instead, no unix root translations. */
    262 #define __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE  0x10
     265#define __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE      0x10
    263266/** @} */
    264267
  • trunk/libc/src/kNIX/b_fsPathResolve.c

    r2929 r3768  
    5252     * Resolve to native path.
    5353     */
    54     int     fInUnixTree;
    55     char    szNativePath[PATH_MAX];
    56     szNativePath[0] = '\0';
    57     rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, &fInUnixTree);
     54    int             fInUnixTree = 0;
     55    char            szNativePath[PATH_MAX];
     56    unsigned int    fBackFsFlags = fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE
     57                                 ? BACKFS_FLAGS_RESOLVE_DIR_MAYBE | BACKFS_FLAGS_RESOLVE_FULL_MAYBE
     58                                 : BACKFS_FLAGS_RESOLVE_DIR_MAYBE | BACKFS_FLAGS_RESOLVE_FULL;
     59    szNativePath[0] = szNativePath[1] = szNativePath[2] = szNativePath[3] = '\0';
     60    rc = __libc_back_fsResolve(pszPath, fBackFsFlags, szNativePath, &fInUnixTree);
    5861
    5962    /*
     
    6164     */
    6265    char *pszSrc = &szNativePath[0];
    63     if (!(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE) && fInUnixTree)
     66    if (   !(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE)
     67        && fInUnixTree
     68        && *pszSrc)
    6469    {
    6570        pszSrc += __libc_gcchUnixRoot;
  • trunk/libc/src/libc/misc/_realrealpath.c

    r2254 r3768  
    3939
    4040/**
    41  * Gets the absolute native path. This is used when path and such is passed on to
    42  * non libc processes.
     41 * Gets the absolute native path.
     42 *
     43 * This is used when path and such is passed on to non-kLibC processes.
    4344 *
    4445 * @returns Pointer to the resolved path.
    4546 * @returns NULL and errno on failure.
    4647 * @param   pszPath     The path to resolve
    47  * @param   pszResolved Where to put the resolved path.
    48  *                      If NULL a fitting buffer is malloc'ed.
    49  * @param   cchResolved Size of the passed in buffer. Minimum size of an allocated buffer.
     48 * @param   pszResolved Where to put the resolved path.  If NULL, a fitting
     49 *                      buffer is malloc'ed.
     50 * @param   cbResolved  Size of the passed in buffer. Minimum size of an
     51 *                      allocated buffer.
    5052 */
    51 char    *_realrealpath(const char *pszPath, char *pszResolved, size_t cchResolved)
     53char    *_realrealpath(const char *pszPath, char *pszResolved, size_t cbResolved)
    5254{
    53     LIBCLOG_ENTER("pszPath=%p:{%s} pszResolved=%p cchResolved=%d\n", (void *)pszPath, pszPath, pszResolved, cchResolved);
     55    LIBCLOG_ENTER("pszPath=%p:{%s} pszResolved=%p cbResolved=%d\n", (void *)pszPath, pszPath, pszResolved, cbResolved);
    5456
    5557    if (!pszPath)
     
    6567        if (psz)
    6668        {
    67             rc = __libc_Back_fsPathResolve(pszPath, psz, PATH_MAX, __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE);
     69            rc = __libc_Back_fsPathResolve(pszPath, psz, PATH_MAX, __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE | __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE);
    6870            if (!rc)
    6971            {
    7072                char *pszOld = psz;
    7173                int cch = strlen(psz) + 1;
    72                 if (cch < cchResolved)
    73                     cch = cchResolved;
     74                if (cch < cbResolved)
     75                    cch = cbResolved;
    7476                psz = realloc(psz, cch);
    7577                if (!psz)
     
    8688
    8789    char *pszRet = pszResolved;
    88     rc = __libc_Back_fsPathResolve(pszPath, pszResolved, cchResolved, __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE);
     90    rc = __libc_Back_fsPathResolve(pszPath, pszResolved, cbResolved, __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE | __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE);
    8991    if (!rc)
    9092        LIBCLOG_RETURN_MSG(pszRet, "ret %p - pszResolved=%p:{%s}\n", pszRet, pszResolved, pszResolved);
  • trunk/libc/src/libc/misc/realpath.c

    r2254 r3768  
    6565        if (psz)
    6666        {
    67             rc = __libc_Back_fsPathResolve(path, psz, PATH_MAX, 0);
     67            rc = __libc_Back_fsPathResolve(path, psz, PATH_MAX, __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE);
    6868            if (!rc)
    6969            {
     
    8484
    8585    char *pszRet = resolved_path;
    86     rc = __libc_Back_fsPathResolve(path, resolved_path, PATH_MAX, 0);
     86    rc = __libc_Back_fsPathResolve(path, resolved_path, PATH_MAX, __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE);
    8787    if (!rc)
    8888        LIBCLOG_RETURN_MSG(pszRet, "ret %p - resolved_path=%p:{%s}\n", pszRet, resolved_path, resolved_path);
Note: See TracChangeset for help on using the changeset viewer.