95 memset( stream, 0,
sizeof(
STREAM ) );
102 static
int checkMemoryStreamParams(
INOUT STREAM *stream,
128 static
int shutdownMemoryStream(
INOUT STREAM *stream,
129 const BOOLEAN clearStreamBuffer )
141 if( clearStreamBuffer && stream->buffer != NULL && stream->bufEnd > 0 )
142 zeroise( stream->buffer, stream->bufEnd );
176 status = initMemoryStream( stream,
FALSE );
178 status = checkMemoryStreamParams( stream, buffer, length );
187 memset( stream->buffer, 0,
min( 16, stream->bufSize ) );
189 memset( stream->buffer, 0, stream->bufSize );
196 int sMemNullOpen(
STREAM *stream )
203 status = initMemoryStream( stream,
TRUE );
216 assert( ( buffer == NULL && length == 0 ) || \
224 return( sMemNullOpen( stream ) );
225 return( sMemOpen( stream, buffer, length ) );
229 int sMemClose(
STREAM *stream )
236 return( shutdownMemoryStream( stream,
TRUE ) );
255 status = initMemoryStream( stream,
FALSE );
257 status = checkMemoryStreamParams( stream, buffer, length );
260 stream->buffer = (
void * ) buffer;
279 return( shutdownMemoryStream( stream,
FALSE ) );
302 assert(
isWritePtr( dataPtrPtr,
sizeof(
void * ) ) );
308 REQUIRES( sanityCheck( stream ) && \
318 return( stream->status );
324 if( position + length < 0 || \
325 position + length > stream->bufSize )
330 *dataPtrPtr = stream->buffer +
position;
360 return( stream->bufSize - stream->bufPos );
371 assert(
isWritePtr( dataPtrPtr,
sizeof(
void * ) ) );
377 return( getMemoryBlock( stream, dataPtrPtr, stream->bufPos, dataSize ) );
389 assert(
isWritePtr( dataPtrPtr,
sizeof(
void * ) ) );
390 assert( position >= 0 && position < stream->
bufSize );
396 return( getMemoryBlock( stream, dataPtrPtr, position, dataSize ) );
400 int sMemGetDataBlockRemaining(
INOUT STREAM *stream,
404 const int dataLeft = sMemDataLeft( stream );
409 assert(
isWritePtr( dataPtrPtr,
sizeof(
void * ) ) );
410 assert(
isWritePtr( length,
sizeof(
int ) ) );
423 status = getMemoryBlock( stream, dataPtrPtr, stream->bufPos, dataLeft );