scmstream.cpp revision e99772f9bf09219c532812c859fbeea513c67e65
* Initialize an input stream. * @returns IPRT status code. * @param pStream The stream to initialize. * @param pszFilename The file to take the stream content from. * Initialize an output stream. * @returns IPRT status code * @param pStream The stream to initialize. * @param pRelatedStream Pointer to a related stream. NULL is fine. * Frees the resources associated with the stream. * Nothing is happens to whatever the stream was initialized from or dumped to. * @param pStream The stream to delete. * Get the stream status code. * @returns IPRT status code. * @param pStream The stream. * Grows the buffer of a write stream. * @returns IPRT status code. * @param pStream The stream. Must be in write mode. * @param cbAppending The minimum number of bytes to grow the buffer * Grows the line array of a stream. * @returns IPRT status code. * @param pStream The stream. * @param iMinLine Minimum line number. * Rewinds the stream and sets the mode to read. * @param pStream The stream. * Rewinds the stream and sets the mode to write. * @param pStream The stream. * Checks if it's a text stream. * @returns true if it probably is a text file, false if not. * @param pStream The stream. Write or read, doesn't matter. * Performs an integrity check of the stream. * @returns IPRT status code. * @param pStream The stream. * Writes the stream to a file. * @returns IPRT status code * @param pStream The stream. * @param pszFilenameFmt The filename format string. * @param ... Format arguments. * Check that what we're going to write makes sense first. * Worker for ScmStreamGetLine that builds the line number index while parsing * @returns Same as SCMStreamGetLine. * @param pStream The stream. Must be in read mode. * @param pcchLine Where to return the line length. * @param penmEol Where to return the kind of end of line marker. * Internal worker that delineates a stream. * @returns IPRT status code. * @param pStream The stream. Caller must check that it is in /* Save the stream position. */ /* Restore the position */ * Get the current stream position as an byte offset. * @returns The current byte offset * @param pStream The stream. * Get the current stream position as a line number. * @returns The current line (0-based). * @param pStream The stream. * Get the current stream size in bytes. * @returns Count of bytes. * @param pStream The stream. * Gets the number of lines in the stream. * @returns The number of lines. * @param pStream The stream. * Seeks to a given byte offset in the stream. * @returns IPRT status code. * @retval VERR_SEEK if the new stream position is the middle of an EOL marker. * This is a temporary restriction. * @param pStream The stream. Must be in read mode. * @param offAbsolute The offset to seek to. If this is beyond the * end of the stream, the position is set to the /* Must be fully delineated. (lazy bird) */ /** @todo Should do a binary search here, but I'm too darn lazy tonight. */ * Seeks a number of bytes relative to the current stream position. * @returns IPRT status code. * @retval VERR_SEEK if the new stream position is the middle of an EOL marker. * This is a temporary restriction. * @param pStream The stream. Must be in read mode. * @param offRelative The offset to seek to. A negative offset * rewinds and positive one fast forwards the * stream. Will quietly stop at the beginning and * Seeks to a given line in the stream. * @returns IPRT status code. * @param pStream The stream. Must be in read mode. * @param iLine The line to seek to. If this is beyond the end * of the stream, the position is set to the end. /* Must be fully delineated. (lazy bird) */ * Get a numbered line from the stream (changes the position). * A line is always delimited by a LF character or the end of the stream. The * delimiter is not included in returned line length, but instead returned via * the @a penmEol indicator. * @returns Pointer to the first character in the line, not NULL terminated. * NULL if the end of the stream has been reached or some problem * @param pStream The stream. Must be in read mode. * @param iLine The line to get (0-based). * @param pcchLine The length. * @param penmEol Where to return the end of line type indicator. /* Make sure it's fully delineated so we can use the index. */ /* update the stream position. */ * Get a line from the stream. * A line is always delimited by a LF character or the end of the stream. The * delimiter is not included in returned line length, but instead returned via * the @a penmEol indicator. * @returns Pointer to the first character in the line, not NULL terminated. * NULL if the end of the stream has been reached or some problem * @param pStream The stream. Must be in read mode. * @param pcchLine The length. * @param penmEol Where to return the end of line type indicator. /** @todo this doesn't work when pStream->off != * pStream->paLines[pStream->iLine-1].pff. */ * Reads @a cbToRead bytes into @a pvBuf. * Will fail if end of stream is encountered before the entire read has been * @returns IPRT status code. * @retval VERR_EOF if there isn't @a cbToRead bytes left to read. Stream * position will be unchanged. * @param pStream The stream. Must be in read mode. * @param pvBuf The buffer to read into. * @param cbToRead The number of bytes to read. /* If there isn't enough stream left, fail already. */ /* Copy the data and simply seek to the new stream position. */ * Checks if the given line is empty or full of white space. * @returns true if white space only, false if not (or if non-existant). * @param pStream The stream. Must be in read mode. * @param iLine The line in question. * Try figure out the end of line style of the give stream. * @returns Most likely end of line style. * @param pStream The stream. * Get the end of line indicator type for a line. * @returns The EOL indicator. If the line isn't found, the default EOL * @param pStream The stream. * @param iLine The line (0-base). * Appends a line to the stream. * @returns IPRT status code. * @param pStream The stream. Must be in write mode. * @param pchLine Pointer to the line. * @param cchLine Line length. * @param enmEol Which end of line indicator to use. * Make sure the previous line has a new-line indicator. * Ensure we've got sufficient buffer space. * @returns IPRT status code * @param pStream The stream. Must be in write mode. * @param pchBuf What to write. * @param cchBuf How much to write. * Ensure we've got sufficient buffer space. * Deal with the odd case where we've already pushed a line with SCMEOL_NONE. * Copy the data and update position and size. * Write a character to the stream. * @returns IPRT status code * @param pStream The stream. Must be in write mode. * @param pchBuf What to write. * @param cchBuf How much to write. * Only deal with the simple cases here, use ScmStreamWrite for the * Copies @a cLines from the @a pSrc stream onto the @a pDst stream. * The stream positions will be used and changed in both streams. * @returns IPRT status code. * @param pDst The destination stream. Must be in write mode. * @param cLines The number of lines. (0 is accepted.) * @param pSrc The source stream. Must be in read mode.