aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2016-04-29 20:30:56 +0000
committerdrh <drh@noemail.net>2016-04-29 20:30:56 +0000
commit2aab11fa5a7eea97a0a7f2fcbbf2432b883c071a (patch)
tree9da98ac6654a9fb61b3e3b21a1b3c8a597c7ae91 /src/os_unix.c
parent54606bbc1487c013a9236267389281d6b74c7e12 (diff)
downloadsqlite-2aab11fa5a7eea97a0a7f2fcbbf2432b883c071a.tar.gz
sqlite-2aab11fa5a7eea97a0a7f2fcbbf2432b883c071a.zip
Fix the temporary directory search algorithm for unix so that it fails
gracefully even if all candidate directories are inaccessible. This fixes a bug that was introduced by check-in [9b8fec60d8e]. FossilOrigin-Name: 614bb709d34e11488da88861243023cc5de4b409
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 01de00e0d..f5b01e995 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -5412,18 +5412,22 @@ static const char *unixTempFileDir(void){
"/tmp",
"."
};
- unsigned int i;
+ unsigned int i = 0;
struct stat buf;
const char *zDir = sqlite3_temp_directory;
if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
- for(i=0; i<=sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
- if( zDir==0 ) continue;
- if( osStat(zDir, &buf) ) continue;
- if( !S_ISDIR(buf.st_mode) ) continue;
- if( osAccess(zDir, 03) ) continue;
- return zDir;
+ while(1){
+ if( zDir!=0
+ && osStat(zDir, &buf)==0
+ && S_ISDIR(buf.st_mode)
+ && osAccess(zDir, 03)==0
+ ){
+ return zDir;
+ }
+ if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
+ zDir = azDirs[i++];
}
return 0;
}