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

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

Issue 1473963002: [sql] Remove part of WebDatabase SQLite patch. (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 5507 matching lines...) Expand 10 before | Expand all | Expand 10 after
5518 struct stat sStat; /* Results of stat() call */ 5518 struct stat sStat; /* Results of stat() call */
5519 5519
5520 /* A stat() call may fail for various reasons. If this happens, it is 5520 /* A stat() call may fail for various reasons. If this happens, it is
5521 ** almost certain that an open() call on the same path will also fail. 5521 ** almost certain that an open() call on the same path will also fail.
5522 ** For this reason, if an error occurs in the stat() call here, it is 5522 ** For this reason, if an error occurs in the stat() call here, it is
5523 ** ignored and -1 is returned. The caller will try to open a new file 5523 ** ignored and -1 is returned. The caller will try to open a new file
5524 ** descriptor on the same path, fail, and return an error to SQLite. 5524 ** descriptor on the same path, fail, and return an error to SQLite.
5525 ** 5525 **
5526 ** Even if a subsequent open() call does succeed, the consequences of 5526 ** Even if a subsequent open() call does succeed, the consequences of
5527 ** not searching for a reusable file descriptor are not dire. */ 5527 ** not searching for a reusable file descriptor are not dire. */
5528 if( 0==osStat(zPath, &sStat) ){ 5528 if( 0==osStat(zPath, &sStat) ){
Scott Hess - ex-Googler 2015/11/25 19:14:54 This is the stat() I mean.
5529 unixInodeInfo *pInode; 5529 unixInodeInfo *pInode;
5530 5530
5531 unixEnterMutex(); 5531 unixEnterMutex();
5532 pInode = inodeList; 5532 pInode = inodeList;
5533 while( pInode && (pInode->fileId.dev!=sStat.st_dev 5533 while( pInode && (pInode->fileId.dev!=sStat.st_dev
5534 || pInode->fileId.ino!=sStat.st_ino) ){ 5534 || pInode->fileId.ino!=sStat.st_ino) ){
5535 pInode = pInode->pNext; 5535 pInode = pInode->pNext;
5536 } 5536 }
5537 if( pInode ){ 5537 if( pInode ){
5538 UnixUnusedFd **pp; 5538 UnixUnusedFd **pp;
(...skipping 98 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 /*
5677 ** Marks 'fd' as the unused file descriptor for 'pFile'. 5647 ** Marks 'fd' as the unused file descriptor for 'pFile'.
5678 */ 5648 */
5679 CHROMIUM_SQLITE_API 5649 CHROMIUM_SQLITE_API
5680 void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file, 5650 void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file,
5681 int fd, 5651 int fd,
5682 int flags) { 5652 int flags) {
5683 unixFile* unixSQLite3File = (unixFile*)file; 5653 unixFile* unixSQLite3File = (unixFile*)file;
5684 if (unixSQLite3File->pUnused) { 5654 if (unixSQLite3File->pUnused) {
5685 unixSQLite3File->pUnused->fd = fd; 5655 unixSQLite3File->pUnused->fd = fd;
5686 unixSQLite3File->pUnused->flags = flags; 5656 unixSQLite3File->pUnused->flags = flags;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5793 ** are harmless. 5763 ** are harmless.
5794 */ 5764 */
5795 if( randomnessPid!=getpid() ){ 5765 if( randomnessPid!=getpid() ){
5796 randomnessPid = getpid(); 5766 randomnessPid = getpid();
5797 sqlite3_randomness(0,0); 5767 sqlite3_randomness(0,0);
5798 } 5768 }
5799 5769
5800 chromium_sqlite3_initialize_unix_sqlite3_file(pFile); 5770 chromium_sqlite3_initialize_unix_sqlite3_file(pFile);
5801 5771
5802 if( eType==SQLITE_OPEN_MAIN_DB ){ 5772 if( eType==SQLITE_OPEN_MAIN_DB ){
5803 rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd); 5773 UnixUnusedFd *pUnused;
5804 if( rc!=SQLITE_OK ){ 5774 pUnused = findReusableFd(zName, flags);
5805 return rc; 5775 if( pUnused ){
5776 fd = pUnused->fd;
5777 }else{
5778 pUnused = sqlite3_malloc(sizeof(*pUnused));
5779 if( !pUnused ){
5780 return SQLITE_NOMEM;
5781 }
5806 } 5782 }
5783 p->pUnused = pUnused;
5807 5784
5808 /* Database filenames are double-zero terminated if they are not 5785 /* Database filenames are double-zero terminated if they are not
5809 ** URIs with parameters. Hence, they can always be passed into 5786 ** URIs with parameters. Hence, they can always be passed into
5810 ** sqlite3_uri_parameter(). */ 5787 ** sqlite3_uri_parameter(). */
5811 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); 5788 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
5812 5789
5813 }else if( !zName ){ 5790 }else if( !zName ){
5814 /* If zName is NULL, the upper layer is requesting a temp file. */ 5791 /* If zName is NULL, the upper layer is requesting a temp file. */
5815 assert(isDelete && !syncDir); 5792 assert(isDelete && !syncDir);
5816 rc = unixGetTempname(MAX_PATHNAME+2, zTmpname); 5793 rc = unixGetTempname(MAX_PATHNAME+2, zTmpname);
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after
7595 ** 7572 **
7596 ** Some operating systems might need to do some cleanup in this routine, 7573 ** Some operating systems might need to do some cleanup in this routine,
7597 ** to release dynamically allocated objects. But not on unix. 7574 ** to release dynamically allocated objects. But not on unix.
7598 ** This routine is a no-op for unix. 7575 ** This routine is a no-op for unix.
7599 */ 7576 */
7600 int sqlite3_os_end(void){ 7577 int sqlite3_os_end(void){
7601 return SQLITE_OK; 7578 return SQLITE_OK;
7602 } 7579 }
7603 7580
7604 #endif /* SQLITE_OS_UNIX */ 7581 #endif /* SQLITE_OS_UNIX */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698