mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Simplify the temporary filename generator and the time-of-day functions in
the unix VFS. FossilOrigin-Name: 6c5621ce1b1a65913b088ed8be65f9b689260d2c
This commit is contained in:
@@ -5424,11 +5424,6 @@ static const char *unixTempFileDir(void){
|
||||
** pVfs->mxPathname bytes.
|
||||
*/
|
||||
static int unixGetTempname(int nBuf, char *zBuf){
|
||||
static const unsigned char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789";
|
||||
unsigned int i, j;
|
||||
const char *zDir;
|
||||
|
||||
/* It's odd to simulate an io-error here, but really this is just
|
||||
@@ -5439,23 +5434,14 @@ static int unixGetTempname(int nBuf, char *zBuf){
|
||||
|
||||
zDir = unixTempFileDir();
|
||||
if( zDir==0 ) zDir = ".";
|
||||
|
||||
/* Check that the output buffer is large enough for the temporary file
|
||||
** name. If it is not, return SQLITE_ERROR.
|
||||
*/
|
||||
if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
do{
|
||||
sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
|
||||
j = (int)strlen(zBuf);
|
||||
sqlite3_randomness(15, &zBuf[j]);
|
||||
for(i=0; i<15; i++, j++){
|
||||
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||
}
|
||||
zBuf[j] = 0;
|
||||
zBuf[j+1] = 0;
|
||||
u64 r;
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
assert( nBuf>2 );
|
||||
zBuf[nBuf-2] = 0;
|
||||
sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
|
||||
zDir, r, 0);
|
||||
if( zBuf[nBuf-2]!=0 ) return SQLITE_ERROR;
|
||||
}while( osAccess(zBuf,0)==0 );
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -6200,11 +6186,8 @@ static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
|
||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
|
||||
#else
|
||||
struct timeval sNow;
|
||||
if( gettimeofday(&sNow, 0)==0 ){
|
||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
|
||||
}else{
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
(void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */
|
||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
|
||||
Reference in New Issue
Block a user