1 /************************************************************************/ 2 /* */ 3 /* An array of bytes and its (maximum) size. */ 4 /* */ 5 /************************************************************************/ 6 7 # ifndef UTIL_MEMORY_H 8 # define UTIL_MEMORY_H 9 10 typedef struct MemoryBuffer 11 { 12 int mbSize; 13 unsigned char * mbBytes; 14 } MemoryBuffer; 15 16 # define utilMemoryBufferIsEmpty( mb ) ( (mb)->mbSize == 0 ) 17 18 /************************************************************************/ 19 /* */ 20 /* Routine declarations. */ 21 /* */ 22 /************************************************************************/ 23 24 extern void utilInitMemoryBuffer( MemoryBuffer * mb ); 25 extern void utilEmptyMemoryBuffer( MemoryBuffer * mb ); 26 extern void utilCleanMemoryBuffer( MemoryBuffer * mb ); 27 28 extern int utilCopyMemoryBuffer( MemoryBuffer * mbTo, 29 const MemoryBuffer * mbFrom ); 30 31 extern int utilMemoryBufferSetSize( MemoryBuffer * mb, 32 int size ); 33 34 extern int utilMemoryBufferSetString( MemoryBuffer * mb, 35 const char * s ) ; 36 37 extern int utilMemoryBufferSetBytes( MemoryBuffer * mb, 38 const unsigned char * bytes, 39 int size ); 40 41 extern const unsigned char * utilMemoryBufferGetBytes( 42 int * pSize, 43 const MemoryBuffer * mbFrom ); 44 45 extern const char * utilMemoryBufferGetString( 46 const MemoryBuffer * mbFrom ); 47 48 extern int utilMemoryCompareBuffers( const MemoryBuffer * mb1, 49 const MemoryBuffer * mb2 ); 50 51 # define utilEqualMemoryBuffer( mb1, mb2 ) \ 52 ( (mb1)->mbSize == (mb2)->mbSize && \ 53 utilMemoryCompareBuffers( (mb1), (mb2) ) == 0 ) 54 55 extern int utilMemoryAppendBuffer( MemoryBuffer * to, 56 const MemoryBuffer * from ); 57 extern int utilMemoryBufferAppendString( MemoryBuffer * to, 58 const char * s ); 59 extern int utilMemoryBufferAppendBytes( MemoryBuffer * mb, 60 const unsigned char * bytes, 61 int size ); 62 63 extern int utilMemoryBufferReplaceBytes( MemoryBuffer * mb, 64 int offHead, 65 int offPast, 66 const unsigned char * addedBytes, 67 int addedCount ); 68 69 extern int utilMemoryBufferGetRange( MemoryBuffer * mbTo, 70 const MemoryBuffer * mbFrom, 71 int offFrom, 72 int lenFrom ); 73 74 extern char * utilMemoryStrdup( const MemoryBuffer * mbFrom ); 75 76 extern int utilMemoryBufferEqualsString( const MemoryBuffer * mb, 77 const char * s ); 78 79 extern int utilMemoryBufferLastIndexOf( const MemoryBuffer * mb, 80 int cal ); 81 82 extern int utilMemoryBufferIndexOf( const MemoryBuffer * mb, 83 int cal ); 84 85 # endif /* UTIL_MEMORY_H */ 86