#pragma once

#include "Utils/Platform.h"

// This header is included by sqlite3 so that we can do interesting things with it without modifying
// the source code in sqlite3.c.

#ifdef POSIX
// Modify calls to fsync and fdatasync (only on Unix), so that we can make them async without doing
// fun things with dlsym and friends. Note that sqlite does "#if defined(fdatasync)" to check if
// someone asks it to trust fdatasync. As such, we can't use the preprocessor. Instead, we define
// static versions of the syscalls (declared 'extern' in system headers). This means that these
// functions are only used by the sqlite3 code.

// Functions to call:
int async_fsync(int fd);
int async_fdatasync(int fd);

static int fsync(int fd) {
	return async_fsync(fd);
}
static int fdatasync(int fd) {
	return async_fdatasync(fd);
}

#endif
