Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

static int kldrDyldFindTryOpenPath ( const char *  pchPath,
KSIZE  cchPath,
PCKLDRDYLDFINDARGS  pArgs 
) [static]

Composes a filename from the specified directory path, prefix (optional), name and suffix (optional, will try with and without).

Parameters:
pchPath The directory path - this doesn't have to be null terminated.
cchPath The length of the path.
pArgs The search argument structure.
Returns:
See kldrDyldFindTryOpen

Definition at line 665 of file kLdrDyldFind.c.

References KLDRDYLDFINDARGS::cchMaxLength, KLDRDYLDFINDARGS::cchName, KLDRDYLDFINDARGS::cchPrefix, KLDRDYLDFINDARGS::cchSuffix, KLDRDYLDFINDARGS::fFlags, K_OS_OS2, K_OS_WINDOWS, KLDR_ERR_MODULE_NOT_FOUND, KLDRDYLD_LOAD_FLAGS_EXECUTABLE, KLDRDYLDFIND_ASSERT, kldrDyldFindTryOpen(), KLDRDYLDFINDARGS::ppRdr, KLDRDYLDFINDARGS::pszName, KLDRDYLDFINDARGS::pszPrefix, and KLDRDYLDFINDARGS::pszSuffix.

Referenced by kldrDyldFindDoDllSearch(), kldrDyldFindDoExeSearch(), and kldrDyldFindEnumeratePath().

{
    static char s_szFilename[1024];
    char *psz;
    int rc;

    /*
     * Ignore any attempts at opening empty paths.
     * This can happen when a *Dir globals is empty.
     */
    if (!cchPath)
        return KLDR_ERR_MODULE_NOT_FOUND; /* ignore */

    /*
     * Limit check first.
     */
    if (cchPath + 1 + pArgs->cchMaxLength >= sizeof(s_szFilename))
    {
        KLDRDYLDFIND_ASSERT(!"too long");
        return KLDR_ERR_MODULE_NOT_FOUND; /* ignore */
    }

    /*
     * The directory path.
     */
    kHlpMemCopy(s_szFilename, pchPath, cchPath);
    psz = &s_szFilename[cchPath];
    if (psz[-1] != '/'
#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
        && psz[-1] != '\\'
        && psz[-1] != ':'
#endif
        )
        *psz++ = '/';

    /*
     * The name.
     */
    if (pArgs->cchPrefix)
    {
        kHlpMemCopy(psz, pArgs->pszPrefix, pArgs->cchPrefix);
        psz += pArgs->cchPrefix;
    }
    kHlpMemCopy(psz, pArgs->pszName, pArgs->cchName);
    psz += pArgs->cchName;
    if (pArgs->cchSuffix)
    {
        kHlpMemCopy(psz, pArgs->pszSuffix, pArgs->cchSuffix);
        psz += pArgs->cchSuffix;
    }
    *psz = '\0';


    /*
     * Try open it.
     */
    rc = kldrDyldFindTryOpen(s_szFilename, pArgs->ppRdr);
    /* If we're opening an executable, try again without the suffix.*/
    if (    rc
        &&  pArgs->cchSuffix
        &&  (pArgs->fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
    {
        psz -= pArgs->cchSuffix;
        *psz = '\0';
        rc = kldrDyldFindTryOpen(s_szFilename, pArgs->ppRdr);
    }
    return rc;
}


Generated by  Doxygen 1.6.0   Back to index