aboutsummaryrefslogtreecommitdiff
path: root/src/membuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/membuf.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/membuf.cpp b/src/membuf.cpp
index 6d850bf..e7c7ac8 100644
--- a/src/membuf.cpp
+++ b/src/membuf.cpp
@@ -41,9 +41,29 @@ size_t Bu::MemBuf::read( void *pBuf, size_t nBytes )
41 41
42size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) 42size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes )
43{ 43{
44 sBuf.append( (const char *)pBuf, nBytes ); 44 if( nPos == sBuf.getSize() )
45 nPos += nBytes; 45 {
46 return nBytes; 46 // Easiest, just append the data.
47 sBuf.append( (const char *)pBuf, nBytes );
48 nPos += nBytes;
49 return nBytes;
50 }
51 else
52 {
53 // Trickier, we must do this in two parts, overwrite, then append
54 // Frist, overwrite.
55 int iOver = sBuf.getSize() - nPos;
56 if( iOver > nBytes )
57 iOver = nBytes;
58 memcpy( sBuf.getStr()+nPos, pBuf, iOver );
59 // Then append
60 if( iOver < nBytes )
61 {
62 sBuf.append( ((const char *)pBuf)+iOver, nBytes-iOver );
63 }
64 nPos += nBytes;
65 return nBytes;
66 }
47} 67}
48 68
49long Bu::MemBuf::tell() 69long Bu::MemBuf::tell()