summaryrefslogtreecommitdiff
path: root/src/file.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-20 18:09:04 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-20 18:09:04 +0000
commit393f1b414746a7f1977971dd7659dd2b47092b11 (patch)
tree81d0ca1ee70ab86a7d79c1991abe5c387b655fb2 /src/file.cpp
parentc259f95bd0e58b247940a339bb9b4b401b4e9438 (diff)
parent7e25a863325dc3e9762397e700030969e093b087 (diff)
downloadlibbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.gz
libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.bz2
libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.xz
libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.zip
Wow! Merged the branch, streams are updated, and there's no more FString, run
the fixstrings.sh script in the support directory to (hopefully) automatically update your projects.
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/file.cpp b/src/file.cpp
index 008b88e..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.
@@ -17,7 +17,7 @@
17 17
18namespace Bu { subExceptionDef( FileException ) } 18namespace Bu { subExceptionDef( FileException ) }
19 19
20Bu::File::File( const Bu::FString &sName, int iFlags ) : 20Bu::File::File( const Bu::String &sName, int iFlags ) :
21 fd( -1 ), 21 fd( -1 ),
22 bEos( true ) 22 bEos( true )
23{ 23{
@@ -59,12 +59,12 @@ void Bu::File::close()
59 } 59 }
60} 60}
61 61
62size_t Bu::File::read( void *pBuf, size_t nBytes ) 62Bu::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
77size_t Bu::File::write( const void *pBuf, size_t nBytes ) 77Bu::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
88long Bu::File::tell() 88Bu::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
96void Bu::File::seek( long offset ) 96void 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
105void Bu::File::setPos( long pos ) 105void 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
114void Bu::File::setPosEnd( long pos ) 114void 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.");
@@ -187,7 +187,7 @@ void Bu::File::setBlocking( bool bBlocking )
187#endif 187#endif
188} 188}
189 189
190Bu::File Bu::File::tempFile( Bu::FString &sName ) 190Bu::File Bu::File::tempFile( Bu::String &sName )
191{ 191{
192 uint32_t iX; 192 uint32_t iX;
193 iX = time( NULL ) + getpid(); 193 iX = time( NULL ) + getpid();
@@ -218,7 +218,7 @@ Bu::File Bu::File::tempFile( Bu::FString &sName )
218 " iterations."); 218 " iterations.");
219} 219}
220 220
221void Bu::File::setSize( long iSize ) 221void 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
230Bu::size Bu::File::getSize() const
231{
232 struct stat st;
233 fstat( fd, &st );
234 return st.st_size;
235}
236
237Bu::size Bu::File::getBlockSize() const
238{
239 struct stat st;
240 fstat( fd, &st );
241 return st.st_blksize;
242}
243
244Bu::String Bu::File::getLocation() const
245{
246 return "to be implemented";
247}
248
230#ifndef WIN32 249#ifndef WIN32
231void Bu::File::chmod( mode_t t ) 250void Bu::File::chmod( mode_t t )
232{ 251{