VirtualBox

Changeset 937 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Feb 15, 2007 8:59:20 PM (18 years ago)
Author:
vboxsync
Message:

RTPathExists.

Location:
trunk/src/VBox/Runtime/r3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/path-posix.cpp

    r537 r937  
    764764}
    765765
     766
     767RTDECL(bool) RTPathExists(const char *pszPath)
     768{
     769    /*
     770     * Validate input.
     771     */
     772    AssertPtrReturn(pszPath, false);
     773    AssertReturn(*pszPath, false);
     774
     775    /*
     776     * Convert the path and check if it exists using stat().
     777     */
     778    char *pszNativePath;
     779    int rc = rtPathToNative(&pszNativePath, pszPath);
     780    if (RT_SUCCESS(rc))
     781    {
     782        struct stat Stat;
     783        if (!stat(pszNativePath, &Stat))
     784            rc = VINF_SUCCESS;
     785        else
     786            rc = VERR_GENERAL_FAILURE;
     787        RTStrFree(pszNativePath);
     788    }
     789    return RT_SUCCESS(rc);
     790}
     791
  • trunk/src/VBox/Runtime/r3/win32/path-win32.cpp

    r1 r937  
    448448}
    449449
     450
     451/**
     452 * Checks if the path exists.
     453 *
     454 * Symbolic links will all be attempted resolved.
     455 *
     456 * @returns true if it exists and false if it doesn't
     457 * @param   pszPath     The path to check.
     458 */
     459RTDECL(bool) RTPathExists(const char *pszPath)
     460{
     461    /*
     462     * Validate input.
     463     */
     464    AssertPtrReturn(pszPath, false);
     465    AssertReturn(*pszPath, false);
     466
     467    /*
     468     * Try query file info.
     469     */
     470#ifndef RT_DONT_CONVERT_FILENAMES
     471    PRTUCS2 puszPath;
     472    int rc = RTStrUtf8ToUcs2(&puszPath, pszPath);
     473    if (RT_SUCCESS(rc))
     474    {
     475        if (GetFileAttributesW(puszPath) == INVALID_FILE_ATTRIBUTES)
     476            rc = VERR_GENERAL_FAILURE;
     477        RTStrUcs2Free(puszPath);
     478    }
     479#else
     480    int rc = VINF_SUCCESS;
     481    if (GetFileAttributesExA(pszPath) == INVALID_FILE_ATTRIBUTES)
     482        rc = VERR_GENERAL_FAILURE;
     483#endif
     484
     485    return RT_SUCCESS(rc);
     486}
     487
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette