summaryrefslogtreecommitdiff
path: root/src/unstable
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2014-10-03 15:54:36 +0000
committerMike Buland <eichlan@xagasoft.com>2014-10-03 15:54:36 +0000
commit0f26ab693e82d1c56ea0be653a8cd670abeb8f89 (patch)
tree34006fd7690a23a7ec49160398390d6c31e642e8 /src/unstable
parentc5f69c22ca51510da1674bf56982f8f1e3ca4a40 (diff)
downloadlibbu++-0f26ab693e82d1c56ea0be653a8cd670abeb8f89.tar.gz
libbu++-0f26ab693e82d1c56ea0be653a8cd670abeb8f89.tar.bz2
libbu++-0f26ab693e82d1c56ea0be653a8cd670abeb8f89.tar.xz
libbu++-0f26ab693e82d1c56ea0be653a8cd670abeb8f89.zip
Tweaked Bu::Uuid loading to pad it's data more cleanly. This will help ensure
that we don't get valgrind errors, and is probably safer in general. Added Bu::ArchiveStream. It could use some tweaks, but as a quick hack it's handy to allow systems that can only read/write from/to streams to work with archives.
Diffstat (limited to 'src/unstable')
-rw-r--r--src/unstable/archivestream.cpp127
-rw-r--r--src/unstable/archivestream.h49
-rw-r--r--src/unstable/uuid.cpp3
3 files changed, 178 insertions, 1 deletions
diff --git a/src/unstable/archivestream.cpp b/src/unstable/archivestream.cpp
new file mode 100644
index 0000000..aa45e50
--- /dev/null
+++ b/src/unstable/archivestream.cpp
@@ -0,0 +1,127 @@
1/*
2 * Copyright (C) 2007-2014 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/archivestream.h"
9
10Bu::ArchiveStream::ArchiveStream( Bu::ArchiveBase &ar ) :
11 ar( ar ),
12 iPos( 0 )
13{
14}
15
16Bu::ArchiveStream::~ArchiveStream()
17{
18}
19
20void Bu::ArchiveStream::close()
21{
22 ar.close();
23}
24
25Bu::size Bu::ArchiveStream::read( void *pBuf, size iBytes )
26{
27 ar.read( pBuf, iBytes );
28 iPos += iBytes;
29 return iBytes;
30}
31
32Bu::size Bu::ArchiveStream::write( const void *pBuf, size iBytes )
33{
34 ar.write( pBuf, iBytes );
35 iPos += iBytes;
36 return iBytes;
37}
38
39Bu::size Bu::ArchiveStream::tell()
40{
41 return iPos;
42}
43
44void Bu::ArchiveStream::seek( Bu::size )
45{
46 throw Bu::UnsupportedException();
47}
48
49void Bu::ArchiveStream::setPos( Bu::size )
50{
51 throw Bu::UnsupportedException();
52}
53
54void Bu::ArchiveStream::setPosEnd( Bu::size )
55{
56 throw Bu::UnsupportedException();
57}
58
59bool Bu::ArchiveStream::isEos()
60{
61 return false;
62}
63
64bool Bu::ArchiveStream::isOpen()
65{
66 return true;
67}
68
69void Bu::ArchiveStream::flush()
70{
71}
72
73bool Bu::ArchiveStream::canRead()
74{
75 return true;
76}
77
78bool Bu::ArchiveStream::canWrite()
79{
80 return true;
81}
82
83bool Bu::ArchiveStream::isReadable()
84{
85 return true;
86}
87
88bool Bu::ArchiveStream::isWritable()
89{
90 return true;
91}
92
93bool Bu::ArchiveStream::isSeekable()
94{
95 return false;
96}
97
98bool Bu::ArchiveStream::isBlocking()
99{
100 return false;
101}
102
103void Bu::ArchiveStream::setBlocking( bool )
104{
105 throw Bu::UnsupportedException();
106}
107
108void Bu::ArchiveStream::setSize( Bu::size )
109{
110 throw Bu::UnsupportedException();
111}
112
113Bu::size Bu::ArchiveStream::getSize() const
114{
115 return iPos;
116}
117
118Bu::size Bu::ArchiveStream::getBlockSize() const
119{
120 return 1;
121}
122
123Bu::String Bu::ArchiveStream::getLocation() const
124{
125 return "Archive";
126}
127
diff --git a/src/unstable/archivestream.h b/src/unstable/archivestream.h
new file mode 100644
index 0000000..a8ef903
--- /dev/null
+++ b/src/unstable/archivestream.h
@@ -0,0 +1,49 @@
1/*
2 * Copyright (C) 2007-2014 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7#ifndef BU_ARCHIVE_STREAM_H
8#define BU_ARCHIVE_STREAM_H
9
10#include "bu/archivebase.h"
11#include "bu/stream.h"
12
13namespace Bu
14{
15 class ArchiveStream : public Stream
16 {
17 public:
18 ArchiveStream( Bu::ArchiveBase &ar );
19 virtual ~ArchiveStream();
20
21 virtual void close();
22 virtual size read( void *pBuf, size iBytes );
23 virtual size write( const void *pBuf, size iBytes );
24 virtual size tell();
25 virtual void seek( size offset );
26 virtual void setPos( size pos );
27 virtual void setPosEnd( size pos );
28 virtual bool isEos();
29 virtual bool isOpen();
30 virtual void flush();
31 virtual bool canRead();
32 virtual bool canWrite();
33 virtual bool isReadable();
34 virtual bool isWritable();
35 virtual bool isSeekable();
36 virtual bool isBlocking();
37 virtual void setBlocking( bool bBlocking=true );
38 virtual void setSize( size iSize );
39 virtual size getSize() const;
40 virtual size getBlockSize() const;
41 virtual Bu::String getLocation() const;
42
43 private:
44 Bu::ArchiveBase &ar;
45 size iPos;
46 };
47}
48
49#endif
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp
index db758d0..22517d7 100644
--- a/src/unstable/uuid.cpp
+++ b/src/unstable/uuid.cpp
@@ -104,7 +104,8 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType )
104 case System: 104 case System:
105#if defined(linux) 105#if defined(linux)
106 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read ); 106 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read );
107 char dat[36]; 107 char dat[37];
108 memset( dat, 0, 37 );
108 fIn.read( dat, 36 ); 109 fIn.read( dat, 36 );
109 id.set( dat ); 110 id.set( dat );
110#elif defined(WIN32) 111#elif defined(WIN32)