aboutsummaryrefslogtreecommitdiff
path: root/src/membuf.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-10-08 16:17:26 +0000
committerMike Buland <eichlan@xagasoft.com>2008-10-08 16:17:26 +0000
commit3f1c8998166466245aee2860197fb4908e55f1a2 (patch)
treeb6d148679bbd87125f03cb723d5b59969b90c733 /src/membuf.cpp
parent5883662909051e99093514483c32e2539a3cf850 (diff)
downloadlibbu++-3f1c8998166466245aee2860197fb4908e55f1a2.tar.gz
libbu++-3f1c8998166466245aee2860197fb4908e55f1a2.tar.bz2
libbu++-3f1c8998166466245aee2860197fb4908e55f1a2.tar.xz
libbu++-3f1c8998166466245aee2860197fb4908e55f1a2.zip
Ok...corrected a problem with new block allocation in nids, and it no longer
goes into an infinite loop while doing certain kinds of read. Also, it zeros out new blocks to make things easier to cope with in the hex editor, it'll probably also compress better. I also fixed Bu::MemBuf so that you can now write to arbitrary places mid-stream.
Diffstat (limited to 'src/membuf.cpp')
-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()