// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT.

//go:build (darwin && amd64) || (darwin && arm64) || (freebsd && 386) || (freebsd && amd64) || (freebsd && arm) || (freebsd && arm64)

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

const AT_RESOLVE_BENEATH = 8192

const ENOTSUP = 45

const IOCPARM_MAX = 8192

const MADV_FREE = 5

const MAP_RESERVED0080 = 128

const MINCORE_INCORE = 1

const MINCORE_MODIFIED = 4

const MINCORE_MODIFIED_OTHER = 16

const MINCORE_REFERENCED = 2

const MINCORE_REFERENCED_OTHER = 8

const NFDBITS = 0

const SF_NOUNLINK = 1048576

type T_RuneRange = struct {
	F__nranges int32
	F__ranges  uintptr
}

type Tdl_info = TDl_info

const UF_HIDDEN = 32768

const UTIME_NOW = -1

const UTIME_OMIT = -2

const _CACHED_RUNES = 256

const _CRMASK = -256

const _CTYPE_A = 256

const _CTYPE_B = 131072

const _CTYPE_C = 512

const _CTYPE_D = 1024

const _CTYPE_G = 2048

const _CTYPE_I = 524288

const _CTYPE_L = 4096

const _CTYPE_P = 8192

const _CTYPE_Q = 2097152

const _CTYPE_R = 262144

const _CTYPE_S = 16384

const _CTYPE_SW0 = 536870912

const _CTYPE_SW1 = 1073741824

const _CTYPE_SW2 = 2147483648

const _CTYPE_SW3 = 3221225472

const _CTYPE_SWM = 3758096384

const _CTYPE_SWS = 30

const _CTYPE_T = 1048576

const _CTYPE_U = 32768

const _CTYPE_X = 65536

const _POSIX2_FORT_RUN = 200112

const _POSIX_MEMLOCK = -1

const _POSIX_THREAD_PROCESS_SHARED = 200112

type _RuneEntry = T_RuneEntry

type _RuneRange = T_RuneRange

const _SC_2_PBS = 59

const _SC_2_PBS_ACCOUNTING = 60

const _SC_2_PBS_CHECKPOINT = 61

const _SC_2_PBS_LOCATE = 62

const _SC_2_PBS_MESSAGE = 63

const _SC_2_PBS_TRACK = 64

const _SC_ADVISORY_INFO = 65

const _SC_ASYNCHRONOUS_IO = 28

const _SC_ATEXIT_MAX = 107

const _SC_BARRIERS = 66

const _SC_CLOCK_SELECTION = 67

const _SC_CPUTIME = 68

const _SC_DELAYTIMER_MAX = 45

const _SC_FILE_LOCKING = 69

const _SC_FSYNC = 38

const _SC_GETGR_R_SIZE_MAX = 70

const _SC_GETPW_R_SIZE_MAX = 71

const _SC_HOST_NAME_MAX = 72

const _SC_IOV_MAX = 56

const _SC_IPV6 = 118

const _SC_LOGIN_NAME_MAX = 73

const _SC_MEMLOCK = 30

const _SC_MEMLOCK_RANGE = 31

const _SC_MEMORY_PROTECTION = 32

const _SC_MESSAGE_PASSING = 33

const _SC_MONOTONIC_CLOCK = 74

const _SC_MQ_OPEN_MAX = 46

const _SC_MQ_PRIO_MAX = 75

const _SC_NPROCESSORS_CONF = 57

const _SC_NPROCESSORS_ONLN = 58

const _SC_PRIORITIZED_IO = 34

const _SC_PRIORITY_SCHEDULING = 35

const _SC_RAW_SOCKETS = 119

const _SC_READER_WRITER_LOCKS = 76

const _SC_REALTIME_SIGNALS = 36

const _SC_REGEXP = 77

const _SC_RTSIG_MAX = 48

const _SC_SEMAPHORES = 37

const _SC_SEM_NSEMS_MAX = 49

const _SC_SEM_VALUE_MAX = 50

const _SC_SHARED_MEMORY_OBJECTS = 39

const _SC_SHELL = 78

const _SC_SIGQUEUE_MAX = 51

const _SC_SPAWN = 79

const _SC_SPIN_LOCKS = 80

const _SC_SPORADIC_SERVER = 81

const _SC_SYMLOOP_MAX = 120

const _SC_SYNCHRONIZED_IO = 40

const _SC_THREADS = 96

const _SC_THREAD_ATTR_STACKADDR = 82

const _SC_THREAD_ATTR_STACKSIZE = 83

const _SC_THREAD_CPUTIME = 84

const _SC_THREAD_DESTRUCTOR_ITERATIONS = 85

const _SC_THREAD_KEYS_MAX = 86

const _SC_THREAD_PRIORITY_SCHEDULING = 89

const _SC_THREAD_PRIO_INHERIT = 87

const _SC_THREAD_PRIO_PROTECT = 88

const _SC_THREAD_PROCESS_SHARED = 90

const _SC_THREAD_SAFE_FUNCTIONS = 91

const _SC_THREAD_SPORADIC_SERVER = 92

const _SC_THREAD_STACK_MIN = 93

const _SC_THREAD_THREADS_MAX = 94

const _SC_TIMEOUTS = 95

const _SC_TIMERS = 41

const _SC_TIMER_MAX = 52

const _SC_TRACE = 97

const _SC_TRACE_EVENT_FILTER = 98

const _SC_TRACE_INHERIT = 99

const _SC_TRACE_LOG = 100

const _SC_TTY_NAME_MAX = 101

const _SC_TYPED_MEMORY_OBJECTS = 102

const _SC_V6_ILP32_OFF32 = 103

const _SC_V6_ILP32_OFFBIG = 104

const _SC_V6_LP64_OFF64 = 105

const _SC_V6_LPBIG_OFFBIG = 106

const _SC_XOPEN_CRYPT = 108

const _SC_XOPEN_ENH_I18N = 109

const _SC_XOPEN_LEGACY = 110

const _SC_XOPEN_REALTIME = 111

const _SC_XOPEN_REALTIME_THREADS = 112

const _SC_XOPEN_SHM = 113

const _SC_XOPEN_STREAMS = 114

const _SC_XOPEN_UNIX = 115

const _SC_XOPEN_VERSION = 116

const _V6_ILP32_OFF32 = -1

const __SIGN = 32768

var _aDateTimeFuncs = [10]TFuncDef{
	0: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1289,
	},
	1: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1309,
	},
	2: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1517,
	},
	3: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1522,
	},
	4: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1527,
	},
	5: {
		FnArg:      int16(-int32(1)),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1536,
	},
	6: {
		FnArg:      int16(2),
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8) | libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)),
		FpUserData: uintptr(unsafe.Pointer(&_sqlite3Config)),
		FzName:     __ccgo_ts + 1545,
	},
	7: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1554,
	},
	8: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1567,
	},
	9: {
		FfuncFlags: libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_BUILTIN) | libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG) | libc.Int32FromInt32(SQLITE_UTF8)),
		FzName:     __ccgo_ts + 1585,
	},
}

// C documentation
//
//	/*
//	** Many system calls are accessed through pointer-to-functions so that
//	** they may be overridden at runtime to facilitate fault injection during
//	** testing and sandboxing.  The following array holds the names and pointers
//	** to all overrideable system calls.
//	*/
var _aSyscall = [29]Tunix_syscall{
	0: {
		FzName: __ccgo_ts + 3540,
	},
	1: {
		FzName: __ccgo_ts + 3545,
	},
	2: {
		FzName: __ccgo_ts + 3551,
	},
	3: {
		FzName: __ccgo_ts + 3558,
	},
	4: {
		FzName: __ccgo_ts + 3565,
	},
	5: {
		FzName: __ccgo_ts + 3570,
	},
	6: {
		FzName: __ccgo_ts + 3576,
	},
	7: {
		FzName: __ccgo_ts + 3586,
	},
	8: {
		FzName: __ccgo_ts + 3592,
	},
	9: {
		FzName: __ccgo_ts + 3597,
	},
	10: {
		FzName: __ccgo_ts + 3603,
	},
	11: {
		FzName: __ccgo_ts + 3611,
	},
	12: {
		FzName: __ccgo_ts + 3617,
	},
	13: {
		FzName: __ccgo_ts + 3624,
	},
	14: {
		FzName: __ccgo_ts + 3633,
	},
	15: {
		FzName: __ccgo_ts + 3640,
	},
	16: {
		FzName: __ccgo_ts + 3650,
	},
	17: {
		FzName: __ccgo_ts + 3657,
	},
	18: {
		FzName: __ccgo_ts + 3671,
	},
	19: {
		FzName: __ccgo_ts + 3677,
	},
	20: {
		FzName: __ccgo_ts + 3683,
	},
	21: {
		FzName: __ccgo_ts + 3690,
	},
	22: {
		FzName: __ccgo_ts + 3698,
	},
	23: {
		FzName: __ccgo_ts + 3703,
	},
	24: {
		FzName: __ccgo_ts + 3710,
	},
	25: {
		FzName: __ccgo_ts + 3717,
	},
	26: {
		FzName: __ccgo_ts + 3729,
	},
	27: {
		FzName: __ccgo_ts + 3738,
	},
	28: {
		FzName: __ccgo_ts + 3744,
	},
}

var _azName = [192]uintptr{
	0:   __ccgo_ts + 1912,
	1:   __ccgo_ts + 1922,
	2:   __ccgo_ts + 1933,
	3:   __ccgo_ts + 1945,
	4:   __ccgo_ts + 1956,
	5:   __ccgo_ts + 1968,
	6:   __ccgo_ts + 1975,
	7:   __ccgo_ts + 1983,
	8:   __ccgo_ts + 1991,
	9:   __ccgo_ts + 1996,
	10:  __ccgo_ts + 2001,
	11:  __ccgo_ts + 2007,
	12:  __ccgo_ts + 2021,
	13:  __ccgo_ts + 2027,
	14:  __ccgo_ts + 2037,
	15:  __ccgo_ts + 2042,
	16:  __ccgo_ts + 2047,
	17:  __ccgo_ts + 2050,
	18:  __ccgo_ts + 2056,
	19:  __ccgo_ts + 2063,
	20:  __ccgo_ts + 2067,
	21:  __ccgo_ts + 2077,
	22:  __ccgo_ts + 2084,
	23:  __ccgo_ts + 2091,
	24:  __ccgo_ts + 2098,
	25:  __ccgo_ts + 2105,
	26:  __ccgo_ts + 2115,
	27:  __ccgo_ts + 2124,
	28:  __ccgo_ts + 2135,
	29:  __ccgo_ts + 2144,
	30:  __ccgo_ts + 2150,
	31:  __ccgo_ts + 2160,
	32:  __ccgo_ts + 2170,
	33:  __ccgo_ts + 2175,
	34:  __ccgo_ts + 2189,
	35:  __ccgo_ts + 2200,
	36:  __ccgo_ts + 2205,
	37:  __ccgo_ts + 2212,
	38:  __ccgo_ts + 2220,
	39:  __ccgo_ts + 2231,
	40:  __ccgo_ts + 2236,
	41:  __ccgo_ts + 2241,
	42:  __ccgo_ts + 2247,
	43:  __ccgo_ts + 2253,
	44:  __ccgo_ts + 2256,
	45:  __ccgo_ts + 2260,
	46:  __ccgo_ts + 2266,
	47:  __ccgo_ts + 2272,
	48:  __ccgo_ts + 2281,
	49:  __ccgo_ts + 2292,
	50:  __ccgo_ts + 2303,
	51:  __ccgo_ts + 2311,
	52:  __ccgo_ts + 2318,
	53:  __ccgo_ts + 2326,
	54:  __ccgo_ts + 2329,
	55:  __ccgo_ts + 2332,
	56:  __ccgo_ts + 2335,
	57:  __ccgo_ts + 2338,
	58:  __ccgo_ts + 2341,
	59:  __ccgo_ts + 2344,
	60:  __ccgo_ts + 2351,
	61:  __ccgo_ts + 2360,
	62:  __ccgo_ts + 2366,
	63:  __ccgo_ts + 2376,
	64:  __ccgo_ts + 2389,
	65:  __ccgo_ts + 2400,
	66:  __ccgo_ts + 2406,
	67:  __ccgo_ts + 2413,
	68:  __ccgo_ts + 2422,
	69:  __ccgo_ts + 2431,
	70:  __ccgo_ts + 2438,
	71:  __ccgo_ts + 2451,
	72:  __ccgo_ts + 2462,
	73:  __ccgo_ts + 2467,
	74:  __ccgo_ts + 2475,
	75:  __ccgo_ts + 2481,
	76:  __ccgo_ts + 2488,
	77:  __ccgo_ts + 2500,
	78:  __ccgo_ts + 2505,
	79:  __ccgo_ts + 2514,
	80:  __ccgo_ts + 2519,
	81:  __ccgo_ts + 2528,
	82:  __ccgo_ts + 2533,
	83:  __ccgo_ts + 2538,
	84:  __ccgo_ts + 2544,
	85:  __ccgo_ts + 2552,
	86:  __ccgo_ts + 2560,
	87:  __ccgo_ts + 2570,
	88:  __ccgo_ts + 2578,
	89:  __ccgo_ts + 2585,
	90:  __ccgo_ts + 2598,
	91:  __ccgo_ts + 2603,
	92:  __ccgo_ts + 2615,
	93:  __ccgo_ts + 2623,
	94:  __ccgo_ts + 2630,
	95:  __ccgo_ts + 2641,
	96:  __ccgo_ts + 2648,
	97:  __ccgo_ts + 2655,
	98:  __ccgo_ts + 2665,
	99:  __ccgo_ts + 2674,
	100: __ccgo_ts + 2685,
	101: __ccgo_ts + 2691,
	102: __ccgo_ts + 2702,
	103: __ccgo_ts + 2712,
	104: __ccgo_ts + 2719,
	105: __ccgo_ts + 2725,
	106: __ccgo_ts + 2735,
	107: __ccgo_ts + 2746,
	108: __ccgo_ts + 2750,
	109: __ccgo_ts + 2759,
	110: __ccgo_ts + 2768,
	111: __ccgo_ts + 2775,
	112: __ccgo_ts + 2785,
	113: __ccgo_ts + 2792,
	114: __ccgo_ts + 2802,
	115: __ccgo_ts + 2811,
	116: __ccgo_ts + 2818,
	117: __ccgo_ts + 2828,
	118: __ccgo_ts + 2836,
	119: __ccgo_ts + 2844,
	120: __ccgo_ts + 2858,
	121: __ccgo_ts + 2872,
	122: __ccgo_ts + 2883,
	123: __ccgo_ts + 2896,
	124: __ccgo_ts + 2907,
	125: __ccgo_ts + 2913,
	126: __ccgo_ts + 2925,
	127: __ccgo_ts + 2934,
	128: __ccgo_ts + 2942,
	129: __ccgo_ts + 2951,
	130: __ccgo_ts + 2960,
	131: __ccgo_ts + 2967,
	132: __ccgo_ts + 2975,
	133: __ccgo_ts + 2982,
	134: __ccgo_ts + 2993,
	135: __ccgo_ts + 3007,
	136: __ccgo_ts + 3018,
	137: __ccgo_ts + 3026,
	138: __ccgo_ts + 3032,
	139: __ccgo_ts + 3040,
	140: __ccgo_ts + 3048,
	141: __ccgo_ts + 3058,
	142: __ccgo_ts + 3071,
	143: __ccgo_ts + 3081,
	144: __ccgo_ts + 3094,
	145: __ccgo_ts + 3103,
	146: __ccgo_ts + 3114,
	147: __ccgo_ts + 3122,
	148: __ccgo_ts + 3128,
	149: __ccgo_ts + 3140,
	150: __ccgo_ts + 3152,
	151: __ccgo_ts + 3160,
	152: __ccgo_ts + 3172,
	153: __ccgo_ts + 3185,
	154: __ccgo_ts + 3195,
	155: __ccgo_ts + 3200,
	156: __ccgo_ts + 3210,
	157: __ccgo_ts + 3222,
	158: __ccgo_ts + 3234,
	159: __ccgo_ts + 3244,
	160: __ccgo_ts + 3250,
	161: __ccgo_ts + 3260,
	162: __ccgo_ts + 3267,
	163: __ccgo_ts + 3279,
	164: __ccgo_ts + 3290,
	165: __ccgo_ts + 3298,
	166: __ccgo_ts + 3307,
	167: __ccgo_ts + 3316,
	168: __ccgo_ts + 3325,
	169: __ccgo_ts + 3332,
	170: __ccgo_ts + 3343,
	171: __ccgo_ts + 3356,
	172: __ccgo_ts + 3366,
	173: __ccgo_ts + 3373,
	174: __ccgo_ts + 3381,
	175: __ccgo_ts + 3390,
	176: __ccgo_ts + 3396,
	177: __ccgo_ts + 3403,
	178: __ccgo_ts + 3411,
	179: __ccgo_ts + 3419,
	180: __ccgo_ts + 3427,
	181: __ccgo_ts + 3437,
	182: __ccgo_ts + 3446,
	183: __ccgo_ts + 3457,
	184: __ccgo_ts + 3468,
	185: __ccgo_ts + 3479,
	186: __ccgo_ts + 3489,
	187: __ccgo_ts + 3495,
	188: __ccgo_ts + 3506,
	189: __ccgo_ts + 3517,
	190: __ccgo_ts + 3522,
	191: __ccgo_ts + 3530,
}

var _azTypes = [5]uintptr{
	0: __ccgo_ts + 1172,
	1: __ccgo_ts + 1184,
	2: __ccgo_ts + 1189,
	3: __ccgo_ts + 1167,
	4: __ccgo_ts + 1703,
}

// C documentation
//
//	/*
//	** The CONCAT(...) function.  Generate a string result that is the
//	** concatentation of all non-null arguments.
//	*/
func _concatFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_concatFuncCore(tls, context, argc, argv, 0, __ccgo_ts+1702)
}

// C documentation
//
//	/*
//	** Lock the file with the lock specified by parameter eFileLock - one
//	** of the following:
//	**
//	**     (1) SHARED_LOCK
//	**     (2) RESERVED_LOCK
//	**     (3) PENDING_LOCK
//	**     (4) EXCLUSIVE_LOCK
//	**
//	** Sometimes when requesting one lock state, additional lock states
//	** are inserted in between.  The locking might fail on one of the later
//	** transitions leaving the lock state different from what it started but
//	** still short of its goal.  The following chart shows the allowed
//	** transitions and the inserted intermediate states:
//	**
//	**    UNLOCKED -> SHARED
//	**    SHARED -> RESERVED
//	**    SHARED -> (PENDING) -> EXCLUSIVE
//	**    RESERVED -> (PENDING) -> EXCLUSIVE
//	**    PENDING -> EXCLUSIVE
//	**
//	** This routine will only increase a lock.  Use the sqlite3OsUnlock()
//	** routine to lower a locking level.
//	**
//	** With dotfile locking, we really only support state (4): EXCLUSIVE.
//	** But we track the other locking levels internally.
//	*/
func _dotlockLock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
	var pFile, zLockFile uintptr
	var rc, tErrno int32
	_, _, _, _ = pFile, rc, tErrno, zLockFile
	pFile = id
	zLockFile = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
	rc = SQLITE_OK
	/* If we have any lock, then the lock file already exists.  All we have
	 ** to do is adjust our internal record of the lock level.
	 */
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) > NO_LOCK {
		(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
		/* Always update the timestamp on the old file */
		libc.Xutimes(tls, zLockFile, libc.UintptrFromInt32(0))
		return SQLITE_OK
	}
	/* grab an exclusive lock */
	rc = (*(*func(*libc.TLS, uintptr, Tmode_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(18)].FpCurrent})))(tls, zLockFile, uint16(0777))
	if rc < 0 {
		/* failed to open/create the lock directory */
		tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
		if int32(EEXIST) == tErrno {
			rc = int32(SQLITE_BUSY)
		} else {
			rc = _sqliteErrorFromPosixError(tls, tErrno, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(15)<<libc.Int32FromInt32(8))
			if rc != int32(SQLITE_BUSY) {
				_storeLastErrno(tls, pFile, tErrno)
			}
		}
		return rc
	}
	/* got it, set the type and return ok */
	(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
	return rc
}

// C documentation
//
//	/*
//	** Lower the locking level on file descriptor pFile to eFileLock.  eFileLock
//	** must be either NO_LOCK or SHARED_LOCK.
//	**
//	** If the locking level of the file descriptor is already at or below
//	** the requested locking level, this routine is a no-op.
//	**
//	** When the locking level reaches NO_LOCK, delete the lock file.
//	*/
func _dotlockUnlock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
	var pFile, zLockFile uintptr
	var rc, tErrno int32
	_, _, _, _ = pFile, rc, tErrno, zLockFile
	pFile = id
	zLockFile = (*TunixFile)(unsafe.Pointer(pFile)).FlockingContext
	/* no-op if possible */
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) == eFileLock {
		return SQLITE_OK
	}
	/* To downgrade to shared, simply update our internal notion of the
	 ** lock state.  No need to mess with the file on disk.
	 */
	if eFileLock == int32(SHARED_LOCK) {
		(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
		return SQLITE_OK
	}
	/* To fully unlock the database, delete the lock file */
	rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(19)].FpCurrent})))(tls, zLockFile)
	if rc < 0 {
		tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
		if tErrno == int32(ENOENT) {
			rc = SQLITE_OK
		} else {
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(8)<<libc.Int32FromInt32(8)
			_storeLastErrno(tls, pFile, tErrno)
		}
		return rc
	}
	(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(NO_LOCK)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the value in pVal interpreted as utf-8 text. Except, if pVal
//	** contains a NULL value, return a pointer to a static string zero
//	** bytes in length instead of a NULL pointer.
//	*/
func _fts5ValueToText(tls *libc.TLS, pVal uintptr) (r uintptr) {
	var zRet, v1 uintptr
	_, _ = zRet, v1
	zRet = Xsqlite3_value_text(tls, pVal)
	if zRet != 0 {
		v1 = zRet
	} else {
		v1 = __ccgo_ts + 1702
	}
	return v1
}

// C documentation
//
//	/*
//	** This function is called whenever processing of the doclist for the
//	** last term on leaf page (pWriter->iBtPage) is completed.
//	**
//	** The doclist-index for that term is currently stored in-memory within the
//	** Fts5SegWriter.aDlidx[] array. If it is large enough, this function
//	** writes it out to disk. Or, if it is too small to bother with, discards
//	** it.
//	**
//	** Fts5SegWriter.btterm currently contains the first term on page iBtPage.
//	*/
func _fts5WriteFlushBtree(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var bFlag int32
	var z, v1 uintptr
	_, _, _ = bFlag, z, v1
	if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage == 0 {
		return
	}
	bFlag = _fts5WriteFlushDlidx(tls, p, pWriter)
	if (*TFts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn > 0 {
			v1 = (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fp
		} else {
			v1 = __ccgo_ts + 1702
		}
		z = v1
		/* The following was already done in fts5WriteInit(): */
		/* sqlite3_bind_int(p->pIdxWriter, 1, pWriter->iSegid); */
		Xsqlite3_bind_blob(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(2), z, (*TFts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn, libc.UintptrFromInt32(0))
		Xsqlite3_bind_int64(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(3), int64(bFlag)+int64((*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage)<<libc.Int32FromInt32(1))
		Xsqlite3_step(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		(*TFts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		Xsqlite3_bind_null(tls, (*TFts5Index)(unsafe.Pointer(p)).FpIdxWriter, int32(2))
	}
	(*TFts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = 0
}

func _groupConcatValue(tls *libc.TLS, context uintptr) {
	var pAccum, pGCC, zText uintptr
	_, _, _ = pAccum, pGCC, zText
	pGCC = Xsqlite3_aggregate_context(tls, context, 0)
	if pGCC != 0 {
		pAccum = pGCC
		if libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(pAccum)).FaccError) == int32(SQLITE_TOOBIG) {
			Xsqlite3_result_error_toobig(tls, context)
		} else {
			if libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(pAccum)).FaccError) == int32(SQLITE_NOMEM) {
				Xsqlite3_result_error_nomem(tls, context)
			} else {
				if (*TGroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 && (*TStrAccum)(unsafe.Pointer(pAccum)).FnChar == uint32(0) {
					Xsqlite3_result_text(tls, context, __ccgo_ts+1702, int32(1), libc.UintptrFromInt32(0))
				} else {
					zText = Xsqlite3_str_value(tls, pAccum)
					Xsqlite3_result_text(tls, context, zText, libc.Int32FromUint32((*TStrAccum)(unsafe.Pointer(pAccum)).FnChar), uintptr(-libc.Int32FromInt32(1)))
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Log an error that is an API call on a connection pointer that should
//	** not have been used.  The "type" of connection pointer is given as the
//	** argument.  The zType is a word like "NULL" or "closed" or "invalid".
//	*/
func _logBadConnection(tls *libc.TLS, zType uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+1850, libc.VaList(bp+8, zType))
}

// C documentation
//
//	/*
//	** Attempt to parse the given string into a julian day number.  Return
//	** the number of errors.
//	**
//	** The following are acceptable forms for the input string:
//	**
//	**      YYYY-MM-DD HH:MM:SS.FFF  +/-HH:MM
//	**      DDDD.DD
//	**      now
//	**
//	** In the first form, the +/-HH:MM is always optional.  The fractional
//	** seconds extension (the ".FFF") is optional.  The seconds portion
//	** (":SS.FFF") is option.  The year and date can be omitted as long
//	** as there is a time string.  The time string can be omitted as long
//	** as there is a year and date.
//	*/
func _parseDateOrTime(tls *libc.TLS, context uintptr, zDate uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* r at bp+0 */ float64
	if _parseYyyyMmDd(tls, zDate, p) == 0 {
		return 0
	} else {
		if _parseHhMmSs(tls, zDate, p) == 0 {
			return 0
		} else {
			if _sqlite3StrICmp(tls, zDate, __ccgo_ts+1226) == 0 && _sqlite3NotPureFunc(tls, context) != 0 {
				return _setDateTimeToCurrent(tls, context, p)
			} else {
				if _sqlite3AtoF(tls, zDate, bp) > 0 {
					_setRawDateNumber(tls, p, **(**float64)(__ccgo_up(bp)))
					return 0
				} else {
					if (_sqlite3StrICmp(tls, zDate, __ccgo_ts+1230) == 0 || _sqlite3StrICmp(tls, zDate, __ccgo_ts+1237) == 0) && _sqlite3NotPureFunc(tls, context) != 0 {
						libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 2, 0x4)
						return _setDateTimeToCurrent(tls, context, p)
					}
				}
			}
		}
	}
	return int32(1)
}

/* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
** Multiplying this by 86400000 gives 464269060799999 as the maximum value
** for DateTime.iJD.
**
** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with
** such a large integer literal, so we have to encode it.
 */

// C documentation
//
//	/*
//	** Close a file descriptor.
//	**
//	** We assume that close() almost always works, since it is only in a
//	** very sick application or on a very sick platform that it might fail.
//	** If it does fail, simply leak the file descriptor, but do log the
//	** error.
//	**
//	** Note that it is not safe to retry close() after EINTR since the
//	** file descriptor might have already been reused by another thread.
//	** So we don't even try to recover from an EINTR.  Just log the error
//	** and move on.
//	*/
func _robust_close(tls *libc.TLS, pFile uintptr, h int32, lineno int32) {
	var v1 uintptr
	_ = v1
	if (*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(1)].FpCurrent})))(tls, h) != 0 {
		if pFile != 0 {
			v1 = (*TunixFile)(unsafe.Pointer(pFile)).FzPath
		} else {
			v1 = uintptr(0)
		}
		_unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(16)<<libc.Int32FromInt32(8), __ccgo_ts+3545, v1, lineno)
	}
}

// C documentation
//
//	/*
//	** Retry ftruncate() calls that fail due to EINTR
//	**
//	** All calls to ftruncate() within this file should be made through
//	** this wrapper.  On the Android platform, bypassing the logic below
//	** could lead to a corrupt database.
//	*/
func _robust_ftruncate(tls *libc.TLS, h int32, sz Tsqlite3_int64) (r int32) {
	var rc int32
	_ = rc
	for cond := true; cond; cond = rc < 0 && **(**int32)(__ccgo_up(libc.X__error(tls))) == int32(EINTR) {
		rc = (*(*func(*libc.TLS, int32, Toff_t) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(6)].FpCurrent})))(tls, h, sz)
	}
	return rc
}

// C documentation
//
//	/*
//	** Use the content of the StrAccum passed as the second argument
//	** as the result of an SQL function.
//	*/
func _sqlite3ResultStrAccum(tls *libc.TLS, pCtx uintptr, p uintptr) {
	if (*TStrAccum)(unsafe.Pointer(p)).FaccError != 0 {
		Xsqlite3_result_error_code(tls, pCtx, libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(p)).FaccError))
		Xsqlite3_str_reset(tls, p)
	} else {
		if libc.Int32FromUint8((*TStrAccum)(unsafe.Pointer(p)).FprintfFlags)&int32(SQLITE_PRINTF_MALLOCED) != 0 {
			Xsqlite3_result_text(tls, pCtx, (*TStrAccum)(unsafe.Pointer(p)).FzText, libc.Int32FromUint32((*TStrAccum)(unsafe.Pointer(p)).FnChar), __ccgo_fp(_sqlite3RowSetClear))
		} else {
			Xsqlite3_result_text(tls, pCtx, __ccgo_ts+1702, 0, libc.UintptrFromInt32(0))
			Xsqlite3_str_reset(tls, p)
		}
	}
}

// C documentation
//
//	/*
//	** Check to make sure we have a valid db pointer.  This test is not
//	** foolproof but it does provide some measure of protection against
//	** misuse of the interface such as passing in db pointers that are
//	** NULL or which have been previously closed.  If this routine returns
//	** 1 it means that the db pointer is valid and 0 if it should not be
//	** dereferenced for any reason.  The calling function should invoke
//	** SQLITE_MISUSE immediately.
//	**
//	** sqlite3SafetyCheckOk() requires that the db pointer be valid for
//	** use.  sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
//	** open properly and is not fit for general use but which can be
//	** used as an argument to sqlite3_errmsg() or sqlite3_close().
//	*/
func _sqlite3SafetyCheckOk(tls *libc.TLS, db uintptr) (r int32) {
	var eOpenState Tu8
	_ = eOpenState
	if db == uintptr(0) {
		_logBadConnection(tls, __ccgo_ts+1703)
		return 0
	}
	eOpenState = (*Tsqlite3)(unsafe.Pointer(db)).FeOpenState
	if libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_OPEN) {
		if _sqlite3SafetyCheckSickOrOk(tls, db) != 0 {
			_logBadConnection(tls, __ccgo_ts+1895)
		}
		return 0
	} else {
		return int32(1)
	}
	return r
}

func _sqlite3SafetyCheckSickOrOk(tls *libc.TLS, db uintptr) (r int32) {
	var eOpenState Tu8
	_ = eOpenState
	eOpenState = (*Tsqlite3)(unsafe.Pointer(db)).FeOpenState
	if libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_SICK) && libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_OPEN) && libc.Int32FromUint8(eOpenState) != int32(SQLITE_STATE_BUSY) {
		_logBadConnection(tls, __ccgo_ts+1904)
		return 0
	} else {
		return int32(1)
	}
	return r
}

var _sqlite3StdType = [6]uintptr{
	0: __ccgo_ts + 1163,
	1: __ccgo_ts + 1167,
	2: __ccgo_ts + 1172,
	3: __ccgo_ts + 1176,
	4: __ccgo_ts + 1184,
	5: __ccgo_ts + 1189,
}

/************** End of global.c **********************************************/
/************** Begin file status.c ******************************************/
/*
** 2008 June 18
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This module implements the sqlite3_status() interface and related
** functionality.
 */
/* #include "sqliteInt.h" */
/************** Include vdbeInt.h in the middle of status.c ******************/
/************** Begin file vdbeInt.h *****************************************/
/*
** 2003 September 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for information that is private to the
** VDBE.  This information used to all be at the top of the single
** source code file "vdbe.c".  When that file became too big (over
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
 */

/*
** The maximum number of times that a statement will try to reparse
** itself before giving up and returning SQLITE_SCHEMA.
 */

/*
** VDBE_DISPLAY_P4 is true or false depending on whether or not the
** "explain" P4 display logic is enabled.
 */

// C documentation
//
//	/*
//	** An array of names of all compile-time options.  This array should
//	** be sorted A-Z.
//	**
//	** This array looks large, but in a typical installation actually uses
//	** only a handful of compile-time options, so most times this array is usually
//	** rather short and uses little memory space.
//	*/
var _sqlite3azCompileOpt = [56]uintptr{
	0:  __ccgo_ts,
	1:  __ccgo_ts + 20,
	2:  __ccgo_ts + 42,
	3:  __ccgo_ts + 61,
	4:  __ccgo_ts + 86,
	5:  __ccgo_ts + 108,
	6:  __ccgo_ts + 138,
	7:  __ccgo_ts + 158,
	8:  __ccgo_ts + 178,
	9:  __ccgo_ts + 201,
	10: __ccgo_ts + 226,
	11: __ccgo_ts + 253,
	12: __ccgo_ts + 278,
	13: __ccgo_ts + 300,
	14: __ccgo_ts + 332,
	15: __ccgo_ts + 358,
	16: __ccgo_ts + 383,
	17: __ccgo_ts + 404,
	18: __ccgo_ts + 422,
	19: __ccgo_ts + 445,
	20: __ccgo_ts + 464,
	21: __ccgo_ts + 483,
	22: __ccgo_ts + 495,
	23: __ccgo_ts + 510,
	24: __ccgo_ts + 532,
	25: __ccgo_ts + 557,
	26: __ccgo_ts + 580,
	27: __ccgo_ts + 602,
	28: __ccgo_ts + 613,
	29: __ccgo_ts + 626,
	30: __ccgo_ts + 641,
	31: __ccgo_ts + 657,
	32: __ccgo_ts + 670,
	33: __ccgo_ts + 691,
	34: __ccgo_ts + 715,
	35: __ccgo_ts + 738,
	36: __ccgo_ts + 754,
	37: __ccgo_ts + 770,
	38: __ccgo_ts + 794,
	39: __ccgo_ts + 821,
	40: __ccgo_ts + 841,
	41: __ccgo_ts + 863,
	42: __ccgo_ts + 885,
	43: __ccgo_ts + 915,
	44: __ccgo_ts + 940,
	45: __ccgo_ts + 966,
	46: __ccgo_ts + 986,
	47: __ccgo_ts + 1012,
	48: __ccgo_ts + 1035,
	49: __ccgo_ts + 1061,
	50: __ccgo_ts + 1083,
	51: __ccgo_ts + 1104,
	52: __ccgo_ts + 1115,
	53: __ccgo_ts + 1123,
	54: __ccgo_ts + 1137,
	55: __ccgo_ts + 1150,
}

// C documentation
//
//	/*
//	** Lock the file with the lock specified by parameter eFileLock - one
//	** of the following:
//	**
//	**     (1) SHARED_LOCK
//	**     (2) RESERVED_LOCK
//	**     (3) PENDING_LOCK
//	**     (4) EXCLUSIVE_LOCK
//	**
//	** Sometimes when requesting one lock state, additional lock states
//	** are inserted in between.  The locking might fail on one of the later
//	** transitions leaving the lock state different from what it started but
//	** still short of its goal.  The following chart shows the allowed
//	** transitions and the inserted intermediate states:
//	**
//	**    UNLOCKED -> SHARED
//	**    SHARED -> RESERVED
//	**    SHARED -> EXCLUSIVE
//	**    RESERVED -> (PENDING) -> EXCLUSIVE
//	**    PENDING -> EXCLUSIVE
//	**
//	** This routine will only increase a lock.  Use the sqlite3OsUnlock()
//	** routine to lower a locking level.
//	*/
func _unixLock(tls *libc.TLS, id uintptr, eFileLock int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pFile, pInode uintptr
	var rc, tErrno, v1 int32
	var _ /* lock at bp+0 */ Tflock
	_, _, _, _, _ = pFile, pInode, rc, tErrno, v1
	/* The following describes the implementation of the various locks and
	 ** lock transitions in terms of the POSIX advisory shared and exclusive
	 ** lock primitives (called read-locks and write-locks below, to avoid
	 ** confusion with SQLite lock names). The algorithms are complicated
	 ** slightly in order to be compatible with Windows95 systems simultaneously
	 ** accessing the same database file, in case that is ever required.
	 **
	 ** Symbols defined in os.h identify the 'pending byte' and the 'reserved
	 ** byte', each single bytes at well known offsets, and the 'shared byte
	 ** range', a range of 510 bytes at a well known offset.
	 **
	 ** To obtain a SHARED lock, a read-lock is obtained on the 'pending
	 ** byte'.  If this is successful, 'shared byte range' is read-locked
	 ** and the lock on the 'pending byte' released.  (Legacy note:  When
	 ** SQLite was first developed, Windows95 systems were still very common,
	 ** and Windows95 lacks a shared-lock capability.  So on Windows95, a
	 ** single randomly selected by from the 'shared byte range' is locked.
	 ** Windows95 is now pretty much extinct, but this work-around for the
	 ** lack of shared-locks on Windows95 lives on, for backwards
	 ** compatibility.)
	 **
	 ** A process may only obtain a RESERVED lock after it has a SHARED lock.
	 ** A RESERVED lock is implemented by grabbing a write-lock on the
	 ** 'reserved byte'.
	 **
	 ** An EXCLUSIVE lock may only be requested after either a SHARED or
	 ** RESERVED lock is held. An EXCLUSIVE lock is implemented by obtaining
	 ** a write-lock on the entire 'shared byte range'. Since all other locks
	 ** require a read-lock on one of the bytes within this range, this ensures
	 ** that no other locks are held on the database.
	 **
	 ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then
	 ** a PENDING lock is obtained first. A PENDING lock is implemented by
	 ** obtaining a write-lock on the 'pending byte'. This ensures that no new
	 ** SHARED locks can be obtained, but existing SHARED locks are allowed to
	 ** persist. If the call to this function fails to obtain the EXCLUSIVE
	 ** lock in this case, it holds the PENDING lock instead. The client may
	 ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED
	 ** locks have cleared.
	 */
	rc = SQLITE_OK
	pFile = id
	tErrno = 0
	/* If there is already a lock of this type or more restrictive on the
	 ** unixFile, do nothing. Don't use the end_lock: exit path, as
	 ** unixEnterMutex() hasn't been called yet.
	 */
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) >= eFileLock {
		return SQLITE_OK
	}
	/* Make sure the locking sequence is correct.
	 **  (1) We never move from unlocked to anything higher than shared lock.
	 **  (2) SQLite never explicitly requests a pending lock.
	 **  (3) A shared lock is always held when a reserve lock is requested.
	 */
	/* This mutex is needed because pFile->pInode is shared across threads
	 */
	pInode = (*TunixFile)(unsafe.Pointer(pFile)).FpInode
	Xsqlite3_mutex_enter(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	/* If some thread using this PID has a lock via a different unixFile*
	 ** handle that precludes the requested lock, return BUSY.
	 */
	if libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) != libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) && (libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) >= int32(PENDING_LOCK) || eFileLock > int32(SHARED_LOCK)) {
		rc = int32(SQLITE_BUSY)
		goto end_lock
	}
	/* If a SHARED lock is requested, and some thread using this PID already
	 ** has a SHARED or RESERVED lock, then increment reference counts and
	 ** return SQLITE_OK.
	 */
	if eFileLock == int32(SHARED_LOCK) && (libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) == int32(SHARED_LOCK) || libc.Int32FromUint8((*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) == int32(RESERVED_LOCK)) {
		(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared + 1
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock + 1
		goto end_lock
	}
	/* A PENDING lock is needed before acquiring a SHARED lock and before
	 ** acquiring an EXCLUSIVE lock.  For the SHARED lock, the PENDING will
	 ** be released.
	 */
	(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(1)
	(**(**Tflock)(__ccgo_up(bp))).Fl_whence = SEEK_SET
	if eFileLock == int32(SHARED_LOCK) || eFileLock == int32(EXCLUSIVE_LOCK) && libc.Int32FromUint8((*TunixFile)(unsafe.Pointer(pFile)).FeFileLock) == int32(RESERVED_LOCK) {
		if eFileLock == int32(SHARED_LOCK) {
			v1 = int32(F_RDLCK)
		} else {
			v1 = int32(F_WRLCK)
		}
		(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(v1)
		(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte)
		if _unixFileLock(tls, pFile, bp) != 0 {
			tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
			rc = _sqliteErrorFromPosixError(tls, tErrno, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(15)<<libc.Int32FromInt32(8))
			if rc != int32(SQLITE_BUSY) {
				_storeLastErrno(tls, pFile, tErrno)
			}
			goto end_lock
		} else {
			if eFileLock == int32(EXCLUSIVE_LOCK) {
				(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(PENDING_LOCK)
				(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(PENDING_LOCK)
			}
		}
	}
	/* If control gets to this point, then actually go ahead and make
	 ** operating system calls for the specified lock.
	 */
	if eFileLock == int32(SHARED_LOCK) {
		/* Now get the read-lock */
		(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte + libc.Int32FromInt32(2))
		(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(SHARED_SIZE)
		if _unixFileLock(tls, pFile, bp) != 0 {
			tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
			rc = _sqliteErrorFromPosixError(tls, tErrno, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(15)<<libc.Int32FromInt32(8))
		}
		/* Drop the temporary PENDING lock */
		(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte)
		(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(1)
		(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_UNLCK)
		if _unixFileLock(tls, pFile, bp) != 0 && rc == SQLITE_OK {
			/* This could happen with a network mount */
			tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
			rc = libc.Int32FromInt32(SQLITE_IOERR) | libc.Int32FromInt32(8)<<libc.Int32FromInt32(8)
		}
		if rc != 0 {
			if rc != int32(SQLITE_BUSY) {
				_storeLastErrno(tls, pFile, tErrno)
			}
			goto end_lock
		} else {
			(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
			(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock = (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnLock + 1
			(*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared = int32(1)
		}
	} else {
		if eFileLock == int32(EXCLUSIVE_LOCK) && (*TunixInodeInfo)(unsafe.Pointer(pInode)).FnShared > int32(1) {
			/* We are trying for an exclusive lock but another thread in this
			 ** same process is still holding a shared lock. */
			rc = int32(SQLITE_BUSY)
		} else {
			if _unixIsSharingShmNode(tls, pFile) != 0 {
				/* We are in WAL mode and attempting to delete the SHM and WAL
				 ** files due to closing the connection or changing out of WAL mode,
				 ** but another process still holds locks on the SHM file, thus
				 ** indicating that database locks have been broken, perhaps due
				 ** to a rogue close(open(dbFile)) or similar.
				 */
				rc = int32(SQLITE_BUSY)
			} else {
				/* The request was for a RESERVED or EXCLUSIVE lock.  It is
				 ** assumed that there is a SHARED or greater lock on the file
				 ** already.
				 */
				(**(**Tflock)(__ccgo_up(bp))).Fl_type = int16(F_WRLCK)
				if eFileLock == int32(RESERVED_LOCK) {
					(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte + libc.Int32FromInt32(1))
					(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(1)
				} else {
					(**(**Tflock)(__ccgo_up(bp))).Fl_start = int64(_sqlite3PendingByte + libc.Int32FromInt32(2))
					(**(**Tflock)(__ccgo_up(bp))).Fl_len = int64(SHARED_SIZE)
				}
				if _unixFileLock(tls, pFile, bp) != 0 {
					tErrno = **(**int32)(__ccgo_up(libc.X__error(tls)))
					rc = _sqliteErrorFromPosixError(tls, tErrno, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(15)<<libc.Int32FromInt32(8))
					if rc != int32(SQLITE_BUSY) {
						_storeLastErrno(tls, pFile, tErrno)
					}
				}
			}
		}
	}
	if rc == SQLITE_OK {
		(*TunixFile)(unsafe.Pointer(pFile)).FeFileLock = libc.Uint8FromInt32(eFileLock)
		(*TunixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = libc.Uint8FromInt32(eFileLock)
	}
	goto end_lock
end_lock:
	;
	Xsqlite3_mutex_leave(tls, (*TunixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	return rc
}

// C documentation
//
//	/*
//	**
//	** This function - unixLogErrorAtLine(), is only ever called via the macro
//	** unixLogError().
//	**
//	** It is invoked after an error occurs in an OS function and errno has been
//	** set. It logs a message using sqlite3_log() containing the current value of
//	** errno and, if possible, the human-readable equivalent from strerror() or
//	** strerror_r().
//	**
//	** The first argument passed to the macro should be the error code that
//	** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
//	** The two subsequent arguments should be the name of the OS function that
//	** failed (e.g. "unlink", "open") and the associated file-system path,
//	** if any.
//	*/
func _unixLogErrorAtLine(tls *libc.TLS, errcode int32, zFunc uintptr, zPath uintptr, iLine int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var iErrno int32
	var zErr uintptr
	_, _ = iErrno, zErr                                 /* Message from strerror() or equivalent */
	iErrno = **(**int32)(__ccgo_up(libc.X__error(tls))) /* Saved syscall error number */
	/* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
	 ** the strerror() function to obtain the human-readable error message
	 ** equivalent to errno. Otherwise, use strerror_r().
	 */
	/* This is a threadsafe build, but strerror_r() is not available. */
	zErr = __ccgo_ts + 1702
	if zPath == uintptr(0) {
		zPath = __ccgo_ts + 1702
	}
	Xsqlite3_log(tls, errcode, __ccgo_ts+3803, libc.VaList(bp+8, iLine, iErrno, zFunc, zPath, zErr))
	return errcode
}

// C documentation
//
//	/*
//	** Truncate an open file to a specified size
//	*/
func _unixTruncate(tls *libc.TLS, id uintptr, nByte Ti64) (r int32) {
	var pFile uintptr
	var rc int32
	_, _ = pFile, rc
	pFile = id
	/* If the user has configured a chunk-size for this file, truncate the
	 ** file so that it consists of an integer number of chunks (i.e. the
	 ** actual file size after the operation may be larger than the requested
	 ** size).
	 */
	if (*TunixFile)(unsafe.Pointer(pFile)).FszChunk > 0 {
		nByte = (nByte + int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk) - int64(1)) / int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk) * int64((*TunixFile)(unsafe.Pointer(pFile)).FszChunk)
	}
	rc = _robust_ftruncate(tls, (*TunixFile)(unsafe.Pointer(pFile)).Fh, nByte)
	if rc != 0 {
		_storeLastErrno(tls, pFile, **(**int32)(__ccgo_up(libc.X__error(tls))))
		return _unixLogErrorAtLine(tls, libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8), __ccgo_ts+3576, (*TunixFile)(unsafe.Pointer(pFile)).FzPath, int32(44166))
	} else {
		/* If the file was just truncated to a size smaller than the currently
		 ** mapped region, reduce the effective mapping size as well. SQLite will
		 ** use read() and write() to access data beyond this point from now on.
		 */
		if nByte < (*TunixFile)(unsafe.Pointer(pFile)).FmmapSize {
			(*TunixFile)(unsafe.Pointer(pFile)).FmmapSize = nByte
		}
		return SQLITE_OK
	}
	return r
}

// C documentation
//
//	/*
//	** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
//	** value of the second argument to nth_value() (eCond==2) has just been
//	** evaluated and the result left in register reg. This function generates VM
//	** code to check that the value is a non-negative integer and throws an
//	** exception if it is not.
//	*/
func _windowCheckValue(tls *libc.TLS, pParse uintptr, reg int32, eCond int32) {
	var regString, regZero int32
	var v uintptr
	_, _, _ = regString, regZero, v
	v = _sqlite3GetVdbe(tls, pParse)
	regZero = _sqlite3GetTempReg(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regZero)
	if eCond >= int32(WINDOW_STARTING_NUM) {
		regString = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, regString, 0, __ccgo_ts+1702, -int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Ge), regString, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), reg)
		_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(libc.Int32FromInt32(SQLITE_AFF_NUMERIC)|libc.Int32FromInt32(SQLITE_JUMPIFNULL)))
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_MustBeInt), reg, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
	}
	_sqlite3VdbeAddOp3(tls, v, _aOp1[eCond], regZero, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), reg)
	_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_AFF_NUMERIC))
	/* NULL case captured by */
	/*   the OP_MustBeInt */
	/* NULL case caught by */
	/*   the OP_Ge */
	_sqlite3MayAbort(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Halt), int32(SQLITE_ERROR), int32(OE_Abort))
	_sqlite3VdbeAppendP4(tls, v, _azErr[eCond], -int32(1))
	_sqlite3ReleaseTempReg(tls, pParse, regZero)
}

type in_addr_t = Tin_addr_t

type in_port_t = Tin_port_t

type vm_offset_t = Tvm_offset_t

type vm_size_t = Tvm_size_t
