Changeset 3550 for trunk/kStuff/kRdr/kRdrBuffered.cpp
- Timestamp:
- Aug 26, 2007, 3:13:35 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/kRdr/kRdrBuffered.cpp
r3548 r3550 60 60 /** The buffer. */ 61 61 KU8 *pbBuf; 62 /** Did we open the pRdr instance or was it handed to us?*/63 KBOOL f OpenedRdr;62 /** Whether the pRdr instance should be closed together with us or not. */ 63 KBOOL fCloseIt; 64 64 /** Set if the buffer has been messed up by kRdrBufLineQ. */ 65 65 KBOOL fTainedByLineQ; … … 354 354 355 355 /* Close the kRdr instance that we're wrapping. */ 356 if (pThis->f OpenedRdr)356 if (pThis->fCloseIt) 357 357 { 358 358 int rc = pThis->pRdr->pOps->pfnDestroy(pThis->pRdr); 359 359 if (rc) 360 360 return rc; 361 pThis->f OpenedRdr= K_FALSE;361 pThis->fCloseIt = K_FALSE; 362 362 pThis->pRdr = NULL; 363 363 } … … 380 380 * Worker for kRdrBufOpen and kRdrBufWrap. 381 381 * 382 * It's essentially kRdrBufWrap without some error checking and an extra argument.382 * It's essentially kRdrBufWrap without error checking. 383 383 * 384 384 * @returns 0 on success, one of the kErrors status code on failure. 385 385 * @param ppRdr Where to store the new file provider instance. 386 386 * @param pRdrWrapped The file provider instance to buffer. 387 * @param f OpenedIt Whether it was opened or not. If set we'll close388 * pRdrWrapped on failure.389 */ 390 static int krdrBufWrapIt(PPKRDR ppRdr, PKRDR pRdrWrapped, KBOOL f OpenedIt)387 * @param fCloseIt Whether it the pRdrWrapped instance should be closed 388 * when the new instance is closed. 389 */ 390 static int krdrBufWrapIt(PPKRDR ppRdr, PKRDR pRdrWrapped, KBOOL fCloseIt) 391 391 { 392 392 PKRDRBUF pThis = (PKRDRBUF)kHlpAlloc(sizeof(*pThis)); … … 400 400 pThis->offBuf = pThis->offBufEnd = 0; 401 401 pThis->cbBufValid = 0; 402 pThis->f OpenedRdr = fOpenedIt;402 pThis->fCloseIt = fCloseIt; 403 403 pThis->fTainedByLineQ = K_FALSE; 404 404 if (pThis->cbFile < 128*1024) … … 416 416 kHlpFree(pThis); 417 417 } 418 if (fOpenedIt)419 kRdrClose(pRdrWrapped);420 418 return KERR_NO_MEMORY; 421 419 } … … 436 434 PKRDR pRdrWrapped; 437 435 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; 442 443 } 443 444 … … 447 448 * 448 449 * @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 */ 455 KRDR_DECL(int) kRdrBufWrap(PPKRDR ppRdr, PKRDR pRdr, KBOOL fCloseIt) 453 456 { 454 457 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 */ 468 KRDR_DECL(KBOOL) kRdrBufIsBuffered(PKRDR pRdr) 469 { 470 KRDR_VALIDATE_EX(pRdr, K_FALSE); 471 return pRdr->pOps == &g_krdrBufOps; 456 472 } 457 473
Note:
See TracChangeset
for help on using the changeset viewer.