scmstream.cpp revision b07b4216b07447c916723417ee9b44f69c2fc11f
af062818b47340eef15700d2f0211576ba3506eevboxsync * IPRT Testcase / Tool - Source Code Massager Stream Code.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (C) 2010-2012 Oracle Corporation
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsync * available from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsync * you can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * General Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
af062818b47340eef15700d2f0211576ba3506eevboxsync/*******************************************************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync* Header Files *
af062818b47340eef15700d2f0211576ba3506eevboxsync*******************************************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync * Initializes the stream structure.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pStream The stream structure.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param fWriteOrRead The value of the fWriteOrRead stream member.
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic void scmStreamInitInternal(PSCMSTREAM pStream, bool fWriteOrRead)
af062818b47340eef15700d2f0211576ba3506eevboxsync * Initialize an input stream.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @returns IPRT status code.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pStream The stream to initialize.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pszFilename The file to take the stream content from.
af062818b47340eef15700d2f0211576ba3506eevboxsyncint ScmStreamInitForReading(PSCMSTREAM pStream, const char *pszFilename)
af062818b47340eef15700d2f0211576ba3506eevboxsync scmStreamInitInternal(pStream, false /*fWriteOrRead*/);
af062818b47340eef15700d2f0211576ba3506eevboxsync int rc = pStream->rc = RTFileReadAll(pszFilename, &pvFile, &cbFile);
af062818b47340eef15700d2f0211576ba3506eevboxsync * Initialize an output stream.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @returns IPRT status code
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pStream The stream to initialize.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pRelatedStream Pointer to a related stream. NULL is fine.
af062818b47340eef15700d2f0211576ba3506eevboxsyncint ScmStreamInitForWriting(PSCMSTREAM pStream, PCSCMSTREAM pRelatedStream)
af062818b47340eef15700d2f0211576ba3506eevboxsync scmStreamInitInternal(pStream, true /*fWriteOrRead*/);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* allocate stuff */
af062818b47340eef15700d2f0211576ba3506eevboxsync size_t cLinesEstimate = pRelatedStream && pRelatedStream->fFullyLineated
af062818b47340eef15700d2f0211576ba3506eevboxsync ? pRelatedStream->cLines + pRelatedStream->cLines / 10
af062818b47340eef15700d2f0211576ba3506eevboxsync pStream->paLines = (PSCMSTREAMLINE)RTMemAlloc(cLinesEstimate * sizeof(SCMSTREAMLINE));
af062818b47340eef15700d2f0211576ba3506eevboxsync * Frees the resources associated with the stream.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Nothing is happens to whatever the stream was initialized from or dumped to.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pStream The stream to delete.
af062818b47340eef15700d2f0211576ba3506eevboxsync RTFileReadAllFree(pStream->pch, pStream->cbAllocated);
af062818b47340eef15700d2f0211576ba3506eevboxsync * Get the stream status code.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @returns IPRT status code.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pStream The stream.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Grows the buffer of a write stream.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @returns IPRT status code.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pStream The stream. Must be in write mode.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param cbAppending The minimum number of bytes to grow the buffer
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic int scmStreamGrowBuffer(PSCMSTREAM pStream, size_t cbAppending)
af062818b47340eef15700d2f0211576ba3506eevboxsync cbAllocated += RT_MAX(0x1000 + cbAppending, cbAllocated);
af062818b47340eef15700d2f0211576ba3506eevboxsync pvNew = RTMemDupEx(pStream->pch, pStream->off, cbAllocated - pStream->off);
return VINF_SUCCESS;
if (!pvNew)
return VINF_SUCCESS;
case SCMEOL_LF:
case SCMEOL_CRLF:
case SCMEOL_NONE:
return VINF_SUCCESS;
int rc;
#ifdef RT_STRICT
return rc;
rc = RTFileOpenV(&hFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE, pszFilenameFmt, va);
return rc;
int rc;
#ifdef RT_STRICT
return rc;
RTHANDLE h;
switch (h.enmType)
case RTHANDLETYPE_FILE:
case RTHANDLETYPE_PIPE:
return rc;
return NULL;
return NULL;
return NULL;
cb--;
return pchRet;
return rc;
return VINF_SUCCESS;
if (offRelative >= 0)
offAbsolute = 0;
return rc;
return VINF_SUCCESS;
const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol)
return NULL;
return NULL;
return NULL;
pStream->off = pStream->paLines[iLine].off + pStream->paLines[iLine].cch + pStream->paLines[iLine].enmEol;
return pchRet;
if ( pszLine
*pcchLine = 0;
return pszLine;
if (pStream->off >= pStream->paLines[iLine].off + pStream->paLines[iLine].cch + pStream->paLines[iLine].enmEol)
return (unsigned)ch;
return (unsigned)ch;
return VERR_EOF;
if (!pchLine)
return cchLine == 0;
return enmEol;
return enmEol;
return rc;
return rc;
return rc;
iLine++;
return VINF_SUCCESS;
return rc;
iLine--;
if (!pchLF)
return rc;
if ( cchLine
cchLine--;
iLine++;
if (!pchLF)
return VINF_SUCCESS;
return VINF_SUCCESS;
char *psz;
if (cch)
return cch;
return cch;
while (cLines-- > 0)
if (!pchLine)
return rc;
return VINF_SUCCESS;
size_t const cchLeft = pStream->paLines[iLine].cch + pStream->paLines[iLine].off - (pStream->off - 1);
return NULL;
char ch;
off++;
return psz;
size_t const cchLeft = pStream->paLines[iLine].cch + pStream->paLines[iLine].off - (pStream->off - 1);
return NULL;
char ch;
off++;
return psz;