diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-10-08 16:17:26 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-10-08 16:17:26 +0000 |
commit | 3f1c8998166466245aee2860197fb4908e55f1a2 (patch) | |
tree | b6d148679bbd87125f03cb723d5b59969b90c733 /src/membuf.cpp | |
parent | 5883662909051e99093514483c32e2539a3cf850 (diff) | |
download | libbu++-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.cpp | 26 |
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 | ||
42 | size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) | 42 | size_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 | ||
49 | long Bu::MemBuf::tell() | 69 | long Bu::MemBuf::tell() |