diff options
author | drh <drh@noemail.net> | 2015-11-25 23:13:14 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-11-25 23:13:14 +0000 |
commit | 970942e4fc734b8a33c1b7c36849c1843f4c9ef5 (patch) | |
tree | 8e9564b7d724423b2b77fdd4563855f0e30eeda2 /src/os_unix.c | |
parent | 489f1e86e3ad5dcf7e2a84c472c752d52355a8f9 (diff) | |
download | sqlite-970942e4fc734b8a33c1b7c36849c1843f4c9ef5.tar.gz sqlite-970942e4fc734b8a33c1b7c36849c1843f4c9ef5.zip |
Simplify the temporary filename generator and the time-of-day functions in
the unix VFS.
FossilOrigin-Name: 6c5621ce1b1a65913b088ed8be65f9b689260d2c
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index 48f38fdfa..3745827f6 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -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 |