aboutsummaryrefslogtreecommitdiff
path: root/src/stable/file.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-05-22 17:15:40 +0000
committerMike Buland <eichlan@xagasoft.com>2012-05-22 17:15:40 +0000
commitce793e31f387c0715fa5b50c20e06510cc3e95ff (patch)
tree5b15972bdcbe7a26933e8158f52b29fb014dc421 /src/stable/file.cpp
parent2295579eb790d6eff6e54e84c01da6de10809a71 (diff)
downloadlibbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.tar.gz
libbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.tar.bz2
libbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.tar.xz
libbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.zip
Moved random to stable, just needs some minor tweaks. But it's already in use
in a couple of core components, including in tempFile name generation.
Diffstat (limited to 'src/stable/file.cpp')
-rw-r--r--src/stable/file.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/stable/file.cpp b/src/stable/file.cpp
index 8d10596..81b476d 100644
--- a/src/stable/file.cpp
+++ b/src/stable/file.cpp
@@ -12,6 +12,7 @@
12#include <fcntl.h> 12#include <fcntl.h>
13#include <unistd.h> 13#include <unistd.h>
14#include <time.h> 14#include <time.h>
15#include "bu/random.h"
15 16
16#include "bu/config.h" 17#include "bu/config.h"
17 18
@@ -190,7 +191,6 @@ void Bu::File::setBlocking( bool bBlocking )
190Bu::File Bu::File::tempFile( Bu::String &sName ) 191Bu::File Bu::File::tempFile( Bu::String &sName )
191{ 192{
192 uint32_t iX; 193 uint32_t iX;
193 iX = time( NULL ) + getpid();
194 int iXes; 194 int iXes;
195 for( iXes = sName.getSize()-1; iXes >= 0; iXes-- ) 195 for( iXes = sName.getSize()-1; iXes >= 0; iXes-- )
196 { 196 {
@@ -200,11 +200,11 @@ Bu::File Bu::File::tempFile( Bu::String &sName )
200 iXes++; 200 iXes++;
201 if( iXes == sName.getSize() ) 201 if( iXes == sName.getSize() )
202 throw Bu::ExceptionBase("Invalid temporary filename template."); 202 throw Bu::ExceptionBase("Invalid temporary filename template.");
203 for( int iter = 0; iter < 100; iter++ ) 203 for( int iter = 0; iter < 1000; iter++ )
204 { 204 {
205 for( int j = iXes; j < sName.getSize(); j++ ) 205 for( int j = iXes; j < sName.getSize(); j++ )
206 { 206 {
207 iX = (1103515245 * iX + 12345); 207 uint32_t iX = Bu::Random::rand();
208 sName[j] = ('A'+(iX%26)) | ((iX&0x1000)?(0x20):(0)); 208 sName[j] = ('A'+(iX%26)) | ((iX&0x1000)?(0x20):(0));
209 } 209 }
210 210
@@ -214,7 +214,7 @@ Bu::File Bu::File::tempFile( Bu::String &sName )
214 |Bu::File::Create|Bu::File::Exclusive ); 214 |Bu::File::Create|Bu::File::Exclusive );
215 } catch(...) { } 215 } catch(...) { }
216 } 216 }
217 throw Bu::FileException("Failed to create unique temporary file after 100" 217 throw Bu::FileException("Failed to create unique temporary file after 1000"
218 " iterations."); 218 " iterations.");
219} 219}
220 220