diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 05:30:43 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 05:30:43 +0000 |
commit | 7c6c9538b03c9eae24e38fbeb30dd76a16aff1d2 (patch) | |
tree | e2d4bfccd81070adf7294ee54db2399df0c7171f /src/file.cpp | |
parent | f5aca1a1b402bd7ebc944dc6e6fe65828d863365 (diff) | |
download | libbu++-7c6c9538b03c9eae24e38fbeb30dd76a16aff1d2.tar.gz libbu++-7c6c9538b03c9eae24e38fbeb30dd76a16aff1d2.tar.bz2 libbu++-7c6c9538b03c9eae24e38fbeb30dd76a16aff1d2.tar.xz libbu++-7c6c9538b03c9eae24e38fbeb30dd76a16aff1d2.zip |
Wow, got the Stream changes propegated, all tests build with string instead of
fstring, and updated the copyright notice to extend to 2011
Diffstat (limited to '')
-rw-r--r-- | src/file.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/file.cpp b/src/file.cpp index 6634a62..09d53de 100644 --- a/src/file.cpp +++ b/src/file.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2007-2010 Xagasoft, All rights reserved. | 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. |
3 | * | 3 | * |
4 | * This file is part of the libbu++ library and is released under the | 4 | * This file is part of the libbu++ library and is released under the |
5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
@@ -59,12 +59,12 @@ void Bu::File::close() | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | size_t Bu::File::read( void *pBuf, size_t nBytes ) | 62 | Bu::size Bu::File::read( void *pBuf, Bu::size nBytes ) |
63 | { | 63 | { |
64 | if( fd < 0 ) | 64 | if( fd < 0 ) |
65 | throw FileException("File not open."); | 65 | throw FileException("File not open."); |
66 | 66 | ||
67 | ssize_t iRead = ::read( fd, pBuf, nBytes ); | 67 | Bu::size iRead = ::read( fd, pBuf, nBytes ); |
68 | if( iRead == 0 ) | 68 | if( iRead == 0 ) |
69 | bEos = true; | 69 | bEos = true; |
70 | else if( iRead == -1 && errno == EAGAIN ) | 70 | else if( iRead == -1 && errno == EAGAIN ) |
@@ -74,18 +74,18 @@ size_t Bu::File::read( void *pBuf, size_t nBytes ) | |||
74 | return iRead; | 74 | return iRead; |
75 | } | 75 | } |
76 | 76 | ||
77 | size_t Bu::File::write( const void *pBuf, size_t nBytes ) | 77 | Bu::size Bu::File::write( const void *pBuf, Bu::size nBytes ) |
78 | { | 78 | { |
79 | if( fd < 0 ) | 79 | if( fd < 0 ) |
80 | throw FileException("File not open."); | 80 | throw FileException("File not open."); |
81 | 81 | ||
82 | ssize_t iWrote = ::write( fd, pBuf, nBytes ); | 82 | Bu::size iWrote = ::write( fd, pBuf, nBytes ); |
83 | if( iWrote < 0 ) | 83 | if( iWrote < 0 ) |
84 | throw FileException( errno, "%s", strerror( errno ) ); | 84 | throw FileException( errno, "%s", strerror( errno ) ); |
85 | return iWrote; | 85 | return iWrote; |
86 | } | 86 | } |
87 | 87 | ||
88 | long Bu::File::tell() | 88 | Bu::size Bu::File::tell() |
89 | { | 89 | { |
90 | if( fd < 0 ) | 90 | if( fd < 0 ) |
91 | throw FileException("File not open."); | 91 | throw FileException("File not open."); |
@@ -93,7 +93,7 @@ long Bu::File::tell() | |||
93 | return lseek( fd, 0, SEEK_CUR ); | 93 | return lseek( fd, 0, SEEK_CUR ); |
94 | } | 94 | } |
95 | 95 | ||
96 | void Bu::File::seek( long offset ) | 96 | void Bu::File::seek( Bu::size offset ) |
97 | { | 97 | { |
98 | if( fd < 0 ) | 98 | if( fd < 0 ) |
99 | throw FileException("File not open."); | 99 | throw FileException("File not open."); |
@@ -102,7 +102,7 @@ void Bu::File::seek( long offset ) | |||
102 | bEos = false; | 102 | bEos = false; |
103 | } | 103 | } |
104 | 104 | ||
105 | void Bu::File::setPos( long pos ) | 105 | void Bu::File::setPos( Bu::size pos ) |
106 | { | 106 | { |
107 | if( fd < 0 ) | 107 | if( fd < 0 ) |
108 | throw FileException("File not open."); | 108 | throw FileException("File not open."); |
@@ -111,7 +111,7 @@ void Bu::File::setPos( long pos ) | |||
111 | bEos = false; | 111 | bEos = false; |
112 | } | 112 | } |
113 | 113 | ||
114 | void Bu::File::setPosEnd( long pos ) | 114 | void Bu::File::setPosEnd( Bu::size pos ) |
115 | { | 115 | { |
116 | if( fd < 0 ) | 116 | if( fd < 0 ) |
117 | throw FileException("File not open."); | 117 | throw FileException("File not open."); |
@@ -218,7 +218,7 @@ Bu::File Bu::File::tempFile( Bu::String &sName ) | |||
218 | " iterations."); | 218 | " iterations."); |
219 | } | 219 | } |
220 | 220 | ||
221 | void Bu::File::setSize( long iSize ) | 221 | void Bu::File::setSize( Bu::size iSize ) |
222 | { | 222 | { |
223 | #ifdef WIN32 | 223 | #ifdef WIN32 |
224 | chsize( fd, iSize ); | 224 | chsize( fd, iSize ); |
@@ -227,6 +227,25 @@ void Bu::File::setSize( long iSize ) | |||
227 | #endif | 227 | #endif |
228 | } | 228 | } |
229 | 229 | ||
230 | Bu::size Bu::File::getSize() const | ||
231 | { | ||
232 | struct stat st; | ||
233 | fstat( fd, &st ); | ||
234 | return st.st_size; | ||
235 | } | ||
236 | |||
237 | Bu::size Bu::File::getBlockSize() const | ||
238 | { | ||
239 | struct stat st; | ||
240 | fstat( fd, &st ); | ||
241 | return st.st_blksize; | ||
242 | } | ||
243 | |||
244 | Bu::String Bu::File::getLocation() const | ||
245 | { | ||
246 | return "to be implemented"; | ||
247 | } | ||
248 | |||
230 | #ifndef WIN32 | 249 | #ifndef WIN32 |
231 | void Bu::File::chmod( mode_t t ) | 250 | void Bu::File::chmod( mode_t t ) |
232 | { | 251 | { |