Update SQLite to configure fsync() at runtime (reapply 997ce29d)

This commit is contained in:
Paul Kulchenko 2022-11-23 18:18:57 -08:00
parent b382e4b93a
commit 9018a16e9f
2 changed files with 14 additions and 4 deletions

View file

@ -47,6 +47,8 @@
#include "libc/stdio/rand.h"
#include "libc/sysv/consts/lock.h"
#include "third_party/sqlite3/sqliteInt.h"
#include "libc/sysv/consts/f.h"
#include "libc/dce.h"
#if SQLITE_OS_UNIX /* This file is used on unix only */
/*
@ -3628,8 +3630,9 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
struct stat buf;
rc = osFstat(fd, &buf);
}
#elif HAVE_FULLFSYNC
if( fullSync ){
#elif HAVE_FULLFSYNC || defined(__COSMOPOLITAN__)
/* [jart] use runtime os detection */
if( fullSync && F_FULLFSYNC != -1 ){
rc = osFcntl(fd, F_FULLFSYNC, 0);
}else{
rc = 1;
@ -3642,7 +3645,13 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
** It'd be better to detect fullfsync support once and avoid
** the fcntl call every time sync is called.
*/
if( rc ) rc = fsync(fd);
if( rc ) {
if( IsXnu() ){
rc = fsync(fd);
}else{
rc = fdatasync(fd);
}
}
#elif defined(__APPLE__)
/* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly

View file

@ -140,7 +140,7 @@ typedef sqlite3_int64 i64;
typedef sqlite3_uint64 u64;
typedef unsigned char u8;
#if SQLITE_USER_AUTHENTICATION
# include "sqlite3userauth.h"
# include "third_party/sqlite3/sqlite3userauth.h"
#endif
#if !defined(_WIN32) && !defined(WIN32)
@ -11265,6 +11265,7 @@ static void process_sqliterc(
p->in = inSaved;
p->lineno = savedLineno;
sqlite3_free(zBuf);
errno = 0; /* [jart] clear error */
}
/*