VirtualBox

Ignore:
Timestamp:
Jul 23, 2013 5:45:07 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87502
Message:

IPRT: Added RTVfsIoStrmOpenNormal and RTVfsFileOpenNormal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp

    r44529 r47356  
    419419
    420420
     421/**
     422 * Internal worker for RTVfsFileFromRTFile and RTVfsFileOpenNormal.
     423 *
     424 * @returns IRPT status code.
     425 * @param   hFile               The IPRT file handle.
     426 * @param   fOpen               The RTFILE_O_XXX flags.
     427 * @param   fLeaveOpen          Whether to leave it open or close it.
     428 * @param   phVfsFile           Where to return the handle.
     429 */
     430static int rtVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile)
     431{
     432    PRTVFSSTDFILE   pThis;
     433    RTVFSFILE       hVfsFile;
     434    int rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, NIL_RTVFSLOCK,
     435                          &hVfsFile, (void **)&pThis);
     436    if (RT_FAILURE(rc))
     437        return rc;
     438
     439    pThis->hFile        = hFile;
     440    pThis->fLeaveOpen   = fLeaveOpen;
     441    *phVfsFile = hVfsFile;
     442    return VINF_SUCCESS;
     443}
     444
     445
    421446RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile)
    422447{
     
    430455
    431456    /*
    432      * Set up some fake fOpen flags.
     457     * Set up some fake fOpen flags if necessary and create a VFS file handle.
    433458     */
    434459    if (!fOpen)
    435460        fOpen = RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_OPEN_CREATE;
    436461
     462    return rtVfsFileFromRTFile(hFile, fOpen, fLeaveOpen, phVfsFile);
     463}
     464
     465
     466RTDECL(int) RTVfsFileOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile)
     467{
    437468    /*
    438      * Create the handle.
     469     * Open the file the normal way and pass it to RTVfsFileFromRTFile.
    439470     */
    440     PRTVFSSTDFILE   pThis;
    441     RTVFSFILE       hVfsFile;
    442     rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, NIL_RTVFSLOCK, &hVfsFile, (void **)&pThis);
    443     if (RT_FAILURE(rc))
    444         return rc;
    445 
    446     pThis->hFile        = hFile;
    447     pThis->fLeaveOpen   = fLeaveOpen;
    448     *phVfsFile = hVfsFile;
    449     return VINF_SUCCESS;
    450 }
    451 
    452 
    453 RTDECL(int)         RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos)
     471    RTFILE hFile;
     472    int rc = RTFileOpen(&hFile, pszFilename, fOpen);
     473    if (RT_SUCCESS(rc))
     474    {
     475        /*
     476         * Create a VFS file handle.
     477         */
     478        rc = rtVfsFileFromRTFile(hFile, fOpen, false /*fLeaveOpen*/, phVfsFile);
     479        if (RT_FAILURE(rc))
     480            RTFileClose(hFile);
     481    }
     482    return rc;
     483}
     484
     485
     486RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos)
    454487{
    455488    RTVFSFILE hVfsFile;
     
    460493}
    461494
     495
     496RTDECL(int) RTVfsIoStrmOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos)
     497{
     498    RTVFSFILE hVfsFile;
     499    int rc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsFile);
     500    if (RT_SUCCESS(rc))
     501        *phVfsIos = RTVfsFileToIoStream(hVfsFile);
     502    return rc;
     503}
     504
     505
Note: See TracChangeset for help on using the changeset viewer.

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