Index: third_party/sqlite/src/src/os_unix.c |
diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/os_unix.c |
index 3ebfa04bbb21f17b8643539cbb59de159a108e30..ef04a72e4528b4a1b45b27a2e8cc373a328e0117 100644 |
--- a/third_party/sqlite/src/src/os_unix.c |
+++ b/third_party/sqlite/src/src/os_unix.c |
@@ -3215,7 +3215,6 @@ static int unixDeviceCharacteristics(sqlite3_file *NotUsed){ |
********************** End sqlite3_file Methods ******************************* |
******************************************************************************/ |
- |
/* |
** This division contains definitions of sqlite3_io_methods objects that |
** implement various file locking strategies. It also contains definitions |
@@ -3813,73 +3812,6 @@ static UnixUnusedFd *findReusableFd(const char *zPath, int flags){ |
} |
/* |
-** Initializes a unixFile structure with zeros. |
-*/ |
-void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file) { |
- memset(file, 0, sizeof(unixFile)); |
-} |
- |
-int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs, |
- int fd, |
- int dirfd, |
- sqlite3_file* file, |
- const char* fileName, |
- int noLock, |
- int isDelete) { |
- return fillInUnixFile(vfs, fd, dirfd, file, fileName, noLock, isDelete); |
-} |
- |
-/* |
-** Search for an unused file descriptor that was opened on the database file. |
-** If a suitable file descriptor if found, then it is stored in *fd; otherwise, |
-** *fd is not modified. |
-** |
-** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot |
-** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned. |
-*/ |
-int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file, |
- const char* fileName, |
- int flags, |
- int* fd) { |
- unixFile* unixSQLite3File = (unixFile*)file; |
- int fileType = flags & 0xFFFFFF00; |
- if (fileType == SQLITE_OPEN_MAIN_DB) { |
- UnixUnusedFd *unusedFd = findReusableFd(fileName, flags); |
- if (unusedFd) { |
- *fd = unusedFd->fd; |
- } else { |
- unusedFd = sqlite3_malloc(sizeof(*unusedFd)); |
- if (!unusedFd) { |
- return SQLITE_NOMEM; |
- } |
- } |
- unixSQLite3File->pUnused = unusedFd; |
- } |
- return SQLITE_OK; |
-} |
- |
-/* |
-** Marks 'fd' as the unused file descriptor for 'pFile'. |
-*/ |
-void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file, |
- int fd, |
- int flags) { |
- unixFile* unixSQLite3File = (unixFile*)file; |
- if (unixSQLite3File->pUnused) { |
- unixSQLite3File->pUnused->fd = fd; |
- unixSQLite3File->pUnused->flags = flags; |
- } |
-} |
- |
-/* |
-** Destroys pFile's field that keeps track of the unused file descriptor. |
-*/ |
-void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file) { |
- unixFile* unixSQLite3File = (unixFile*)file; |
- sqlite3_free(unixSQLite3File->pUnused); |
-} |
- |
-/* |
** Open the file zPath. |
** |
** Previously, the SQLite OS layer used three functions in place of this |
@@ -3961,13 +3893,20 @@ static int unixOpen( |
|| eType==SQLITE_OPEN_TRANSIENT_DB |
); |
- chromium_sqlite3_initialize_unix_sqlite3_file(pFile); |
+ memset(p, 0, sizeof(unixFile)); |
if( eType==SQLITE_OPEN_MAIN_DB ){ |
- rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd); |
- if( rc!=SQLITE_OK ){ |
- return rc; |
+ UnixUnusedFd *pUnused; |
+ pUnused = findReusableFd(zName, flags); |
+ if( pUnused ){ |
+ fd = pUnused->fd; |
+ }else{ |
+ pUnused = sqlite3_malloc(sizeof(*pUnused)); |
+ if( !pUnused ){ |
+ return SQLITE_NOMEM; |
+ } |
} |
+ p->pUnused = pUnused; |
}else if( !zName ){ |
/* If zName is NULL, the upper layer is requesting a temp file. */ |
assert(isDelete && !isOpenDirectory); |
@@ -4010,7 +3949,10 @@ static int unixOpen( |
*pOutFlags = flags; |
} |
- chromium_sqlite3_update_reusable_file_handle(pFile, fd, flags); |
+ if( p->pUnused ){ |
+ p->pUnused->fd = fd; |
+ p->pUnused->flags = flags; |
+ } |
if( isDelete ){ |
#if OS_VXWORKS |
@@ -4082,11 +4024,11 @@ static int unixOpen( |
} |
} |
#endif |
- |
+ |
rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete); |
open_finished: |
if( rc!=SQLITE_OK ){ |
- chromium_sqlite3_destroy_reusable_file_handle(pFile); |
+ sqlite3_free(p->pUnused); |
} |
return rc; |
} |