Ignore:
Timestamp:
Aug 26, 2007, 3:13:35 AM (18 years ago)
Author:
bird
Message:

made kDbg compile again (not linking yet though).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/kRdr/kRdrBuffered.cpp

    r3548 r3550  
    6060    /** The buffer. */
    6161    KU8                *pbBuf;
    62     /** Did we open the pRdr instance or was it handed to us? */
    63     KBOOL               fOpenedRdr;
     62    /** Whether the pRdr instance should be closed together with us or not. */
     63    KBOOL               fCloseIt;
    6464    /** Set if the buffer has been messed up by kRdrBufLineQ. */
    6565    KBOOL               fTainedByLineQ;
     
    354354
    355355    /* Close the kRdr instance that we're wrapping. */
    356     if (pThis->fOpenedRdr)
     356    if (pThis->fCloseIt)
    357357    {
    358358        int rc = pThis->pRdr->pOps->pfnDestroy(pThis->pRdr);
    359359        if (rc)
    360360            return rc;
    361         pThis->fOpenedRdr = K_FALSE;
     361        pThis->fCloseIt = K_FALSE;
    362362        pThis->pRdr = NULL;
    363363    }
     
    380380 * Worker for kRdrBufOpen and kRdrBufWrap.
    381381 *
    382  * It's essentially kRdrBufWrap without some error checking and an extra argument.
     382 * It's essentially kRdrBufWrap without error checking.
    383383 *
    384384 * @returns 0 on success, one of the kErrors status code on failure.
    385385 * @param   ppRdr           Where to store the new file provider instance.
    386386 * @param   pRdrWrapped     The file provider instance to buffer.
    387  * @param   fOpenedIt       Whether it was opened or not. If set we'll close
    388  *                          pRdrWrapped on failure.
    389  */
    390 static int krdrBufWrapIt(PPKRDR ppRdr, PKRDR pRdrWrapped, KBOOL fOpenedIt)
     387 * @param   fCloseIt        Whether it the pRdrWrapped instance should be closed
     388 *                          when the new instance is closed.
     389 */
     390static int krdrBufWrapIt(PPKRDR ppRdr, PKRDR pRdrWrapped, KBOOL fCloseIt)
    391391{
    392392    PKRDRBUF pThis = (PKRDRBUF)kHlpAlloc(sizeof(*pThis));
     
    400400        pThis->offBuf = pThis->offBufEnd = 0;
    401401        pThis->cbBufValid = 0;
    402         pThis->fOpenedRdr = fOpenedIt;
     402        pThis->fCloseIt = fCloseIt;
    403403        pThis->fTainedByLineQ = K_FALSE;
    404404        if (pThis->cbFile < 128*1024)
     
    416416        kHlpFree(pThis);
    417417    }
    418     if (fOpenedIt)
    419         kRdrClose(pRdrWrapped);
    420418    return KERR_NO_MEMORY;
    421419}
     
    436434    PKRDR pRdrWrapped;
    437435    int rc = kRdrOpen(&pRdrWrapped, pszFilename);
    438     if (rc)
    439         return rc;
    440 
    441     return krdrBufWrapIt(ppRdr, pRdrWrapped, K_TRUE);
     436    if (!rc)
     437    {
     438        rc = krdrBufWrapIt(ppRdr, pRdrWrapped, K_TRUE);
     439        if (rc)
     440            kRdrClose(pRdrWrapped);
     441    }
     442    return rc;
    442443}
    443444
     
    447448 *
    448449 * @returns 0 on success, KERR_* on failure.
    449  * @param   ppRdr
    450  * @param   pRdr
    451  */
    452 KRDR_DECL(int) kRdrBufWrap(PPKRDR ppRdr, PKRDR pRdr)
     450 * @param   ppRdr           Where to store the new file provider pointer.
     451 * @param   pRdr            The file provider instance to wrap.
     452 * @param   fCLoseIt        Whether it the wrapped reader should be automatically
     453 *                          closed when the wrapper closes.
     454 */
     455KRDR_DECL(int) kRdrBufWrap(PPKRDR ppRdr, PKRDR pRdr, KBOOL fCloseIt)
    453456{
    454457    KRDR_VALIDATE(pRdr);
    455     return krdrBufWrapIt(ppRdr, pRdr, K_FALSE);
     458    return krdrBufWrapIt(ppRdr, pRdr, fCloseIt);
     459}
     460
     461
     462/**
     463 * Checks whether the file provider instance is of the buffered type or not.
     464 *
     465 * @returns K_TRUE if it is, otherwise K_FALSE.
     466 * @param   pRdr            The file provider instance to check.
     467 */
     468KRDR_DECL(KBOOL) kRdrBufIsBuffered(PKRDR pRdr)
     469{
     470    KRDR_VALIDATE_EX(pRdr, K_FALSE);
     471    return pRdr->pOps == &g_krdrBufOps;
    456472}
    457473
Note: See TracChangeset for help on using the changeset viewer.