Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/sqlite/src/src/os_unix.c

Issue 1485603003: Revert of "[sql] Remove part of WebDatabase SQLite patch." (patchset #1 of https://codereview.chrom… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2004 May 22 2 ** 2004 May 22
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 5626 matching lines...) Expand 10 before | Expand all | Expand 10 after
5637 int fd, 5637 int fd,
5638 int dirfd, 5638 int dirfd,
5639 sqlite3_file* file, 5639 sqlite3_file* file,
5640 const char* fileName, 5640 const char* fileName,
5641 int noLock) { 5641 int noLock) {
5642 int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0); 5642 int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0);
5643 return fillInUnixFile(vfs, fd, file, fileName, ctrlFlags); 5643 return fillInUnixFile(vfs, fd, file, fileName, ctrlFlags);
5644 } 5644 }
5645 5645
5646 /* 5646 /*
5647 ** Search for an unused file descriptor that was opened on the database file.
5648 ** If a suitable file descriptor if found, then it is stored in *fd; otherwise,
5649 ** *fd is not modified.
5650 **
5651 ** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot
5652 ** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned.
5653 */
5654 CHROMIUM_SQLITE_API
5655 int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file,
5656 const char* fileName,
5657 int flags,
5658 int* fd) {
5659 unixFile* unixSQLite3File = (unixFile*)file;
5660 int fileType = flags & 0xFFFFFF00;
5661 if (fileType == SQLITE_OPEN_MAIN_DB) {
5662 UnixUnusedFd *unusedFd = findReusableFd(fileName, flags);
5663 if (unusedFd) {
5664 *fd = unusedFd->fd;
5665 } else {
5666 unusedFd = sqlite3_malloc(sizeof(*unusedFd));
5667 if (!unusedFd) {
5668 return SQLITE_NOMEM;
5669 }
5670 }
5671 unixSQLite3File->pUnused = unusedFd;
5672 }
5673 return SQLITE_OK;
5674 }
5675
5676 /*
5647 ** Marks 'fd' as the unused file descriptor for 'pFile'. 5677 ** Marks 'fd' as the unused file descriptor for 'pFile'.
5648 */ 5678 */
5649 CHROMIUM_SQLITE_API 5679 CHROMIUM_SQLITE_API
5650 void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file, 5680 void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file,
5651 int fd, 5681 int fd,
5652 int flags) { 5682 int flags) {
5653 unixFile* unixSQLite3File = (unixFile*)file; 5683 unixFile* unixSQLite3File = (unixFile*)file;
5654 if (unixSQLite3File->pUnused) { 5684 if (unixSQLite3File->pUnused) {
5655 unixSQLite3File->pUnused->fd = fd; 5685 unixSQLite3File->pUnused->fd = fd;
5656 unixSQLite3File->pUnused->flags = flags; 5686 unixSQLite3File->pUnused->flags = flags;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5763 ** are harmless. 5793 ** are harmless.
5764 */ 5794 */
5765 if( randomnessPid!=getpid() ){ 5795 if( randomnessPid!=getpid() ){
5766 randomnessPid = getpid(); 5796 randomnessPid = getpid();
5767 sqlite3_randomness(0,0); 5797 sqlite3_randomness(0,0);
5768 } 5798 }
5769 5799
5770 chromium_sqlite3_initialize_unix_sqlite3_file(pFile); 5800 chromium_sqlite3_initialize_unix_sqlite3_file(pFile);
5771 5801
5772 if( eType==SQLITE_OPEN_MAIN_DB ){ 5802 if( eType==SQLITE_OPEN_MAIN_DB ){
5773 UnixUnusedFd *pUnused; 5803 rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd);
5774 pUnused = findReusableFd(zName, flags); 5804 if( rc!=SQLITE_OK ){
5775 if( pUnused ){ 5805 return rc;
5776 fd = pUnused->fd;
5777 }else{
5778 pUnused = sqlite3_malloc(sizeof(*pUnused));
5779 if( !pUnused ){
5780 return SQLITE_NOMEM;
5781 }
5782 } 5806 }
5783 p->pUnused = pUnused;
5784 5807
5785 /* Database filenames are double-zero terminated if they are not 5808 /* Database filenames are double-zero terminated if they are not
5786 ** URIs with parameters. Hence, they can always be passed into 5809 ** URIs with parameters. Hence, they can always be passed into
5787 ** sqlite3_uri_parameter(). */ 5810 ** sqlite3_uri_parameter(). */
5788 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); 5811 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
5789 5812
5790 }else if( !zName ){ 5813 }else if( !zName ){
5791 /* If zName is NULL, the upper layer is requesting a temp file. */ 5814 /* If zName is NULL, the upper layer is requesting a temp file. */
5792 assert(isDelete && !syncDir); 5815 assert(isDelete && !syncDir);
5793 rc = unixGetTempname(MAX_PATHNAME+2, zTmpname); 5816 rc = unixGetTempname(MAX_PATHNAME+2, zTmpname);
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after
7572 ** 7595 **
7573 ** Some operating systems might need to do some cleanup in this routine, 7596 ** Some operating systems might need to do some cleanup in this routine,
7574 ** to release dynamically allocated objects. But not on unix. 7597 ** to release dynamically allocated objects. But not on unix.
7575 ** This routine is a no-op for unix. 7598 ** This routine is a no-op for unix.
7576 */ 7599 */
7577 int sqlite3_os_end(void){ 7600 int sqlite3_os_end(void){
7578 return SQLITE_OK; 7601 return SQLITE_OK;
7579 } 7602 }
7580 7603
7581 #endif /* SQLITE_OS_UNIX */ 7604 #endif /* SQLITE_OS_UNIX */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698