VirtualBox

Changeset 22516 in vbox


Ignore:
Timestamp:
Aug 27, 2009 12:42:16 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: Added RTFileExists

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/file.h

    r21801 r22516  
    5454
    5555#ifdef IN_RING3
     56
     57/**
     58 * Checks if the specified file name exists and is a regular file.
     59 *
     60 * Symbolic links will be resolved.
     61 *
     62 * @returns true if it's a regular file, false if it isn't.
     63 * @param   pszPath         The path to the file.
     64 *
     65 * @sa      RTDirExists, RTPathExists, RTSymlinkExists.
     66 */
     67RTDECL(bool) RTFileExists(const char *pszPath);
     68
    5669
    5770/** @name Open flags
  • trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp

    r21616 r22516  
    9090
    9191
     92RTDECL(bool) RTFileExists(const char *pszPath)
     93{
     94    bool fRc = false;
     95    char *pszNativePath;
     96    int rc = rtPathToNative(&pszNativePath, pszPath);
     97    if (RT_SUCCESS(rc))
     98    {
     99        struct stat s;
     100        fRc = !stat(pszNativePath, &s)
     101            && S_ISREG(s.st_mode);
     102
     103        rtPathFreeNative(pszNativePath);
     104    }
     105
     106    LogFlow(("RTFileExists(%p={%s}): returns %RTbool\n", pszPath, pszPath, fRc));
     107    return fRc;
     108}
     109
     110
    92111RTR3DECL(int)  RTFileOpen(PRTFILE pFile, const char *pszFilename, unsigned fOpen)
    93112{
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r21616 r22516  
    6969 * @param   uMethod     Seek method. (The windows one!)
    7070 */
    71 inline bool MySetFilePointer(RTFILE File, uint64_t offSeek, uint64_t *poffNew, unsigned uMethod)
     71DECLINLINE(bool) MySetFilePointer(RTFILE File, uint64_t offSeek, uint64_t *poffNew, unsigned uMethod)
    7272{
    7373    bool            fRc;
     
    126126
    127127    return fIsBeyondLimit;
     128}
     129
     130
     131RTDECL(bool) RTFileExists(const char *pszPath)
     132{
     133    bool fRc = false;
     134
     135    /*
     136     * Convert to UTF-16.
     137     */
     138    PRTUTF16 pwszString;
     139    int rc = RTStrToUtf16(pszPath, &pwszString);
     140    AssertRC(rc);
     141    if (RT_SUCCESS(rc))
     142    {
     143        /*
     144         * Query and check attributes.
     145         */
     146        DWORD dwAttr = GetFileAttributesW((LPCWSTR)pwszString);
     147        fRc = dwAttr != INVALID_FILE_ATTRIBUTES
     148            && !(dwAttr & (  FILE_ATTRIBUTE_DIRECTORY
     149                           | FILE_ATTRIBUTE_DEVICE
     150                           | FILE_ATTRIBUTE_REPARSE_POINT));
     151        RTUtf16Free(pwszString);
     152    }
     153
     154    LogFlow(("RTFileExists(%p:{%s}): returns %RTbool\n", pszPath, pszPath, fRc));
     155    return fRc;
    128156}
    129157
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