// 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) || (linux && 386) || (linux && amd64) || (linux && arm) || (linux && arm64) || (linux && loong64) || (linux && ppc64le) || (linux && riscv64) || (netbsd && amd64) || (openbsd && amd64) || (openbsd && arm64) || (windows && (amd64 || arm64)) || (windows && 386)

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

const SQLITE_BIGENDIAN = 0

const SQLITE_BYTEORDER = 1234

const SQLITE_LITTLEENDIAN = 1

const SQLITE_UTF16NATIVE = 2

// C documentation
//
//	/*
//	** This routine is the same as the sqlite3_complete() routine described
//	** above, except that the parameter is required to be UTF-16 encoded, not
//	** UTF-8.
//	*/
func Xsqlite3_complete16(tls *libc.TLS, zSql uintptr) (r int32) {
	var pVal, zSql8 uintptr
	var rc int32
	_, _, _ = pVal, rc, zSql8
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	pVal = _sqlite3ValueNew(tls, uintptr(0))
	_sqlite3ValueSetStr(tls, pVal, -int32(1), zSql, uint8(SQLITE_UTF16LE), libc.UintptrFromInt32(0))
	zSql8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zSql8 != 0 {
		rc = Xsqlite3_complete(tls, zSql8)
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	_sqlite3ValueFree(tls, pVal)
	return rc & int32(0xff)
}

/************** End of rtree.h ***********************************************/
/************** Continuing where we left off in main.c ***********************/

func Xsqlite3_create_function16(tls *libc.TLS, db uintptr, zFunctionName uintptr, nArg int32, eTextRep int32, p uintptr, __ccgo_fp_xSFunc uintptr, __ccgo_fp_xStep uintptr, __ccgo_fp_xFinal uintptr) (r int32) {
	var rc int32
	var zFunc8 uintptr
	_, _ = rc, zFunc8
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	zFunc8 = _sqlite3Utf16to8(tls, db, zFunctionName, -int32(1), uint8(SQLITE_UTF16LE))
	rc = _sqlite3CreateFunc(tls, db, zFunc8, nArg, eTextRep, p, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, uintptr(0), uintptr(0), uintptr(0))
	_sqlite3DbFree(tls, db, zFunc8)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_result_error16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32) {
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = int32(SQLITE_ERROR)
	_sqlite3VdbeMemSetStr(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, z, int64(n), uint8(SQLITE_UTF16LE), uintptr(-libc.Int32FromInt32(1)))
}

func Xsqlite3_value_bytes16(tls *libc.TLS, pVal uintptr) (r int32) {
	return _sqlite3ValueBytes(tls, pVal, uint8(SQLITE_UTF16LE))
}

func Xsqlite3_value_text16(tls *libc.TLS, pVal uintptr) (r uintptr) {
	return _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF16LE))
}

const __BYTE_ORDER__ = 1234

func _readCoord(tls *libc.TLS, p uintptr, pCoord uintptr) {
	*(*Tu32)(unsafe.Pointer(pCoord)) = uint32(**(**Tu8)(__ccgo_up(p)))<<libc.Int32FromInt32(24) + uint32(**(**Tu8)(__ccgo_up(p + 1)))<<libc.Int32FromInt32(16) + uint32(**(**Tu8)(__ccgo_up(p + 2)))<<libc.Int32FromInt32(8) + uint32(**(**Tu8)(__ccgo_up(p + 3)))<<libc.Int32FromInt32(0)
}

func _sqlite3Put4byte(tls *libc.TLS, p uintptr, v Tu32) {
	**(**uint8)(__ccgo_up(p)) = uint8(v >> libc.Int32FromInt32(24))
	**(**uint8)(__ccgo_up(p + 1)) = uint8(v >> libc.Int32FromInt32(16))
	**(**uint8)(__ccgo_up(p + 2)) = uint8(v >> libc.Int32FromInt32(8))
	**(**uint8)(__ccgo_up(p + 3)) = uint8(v)
}

func _writeCoord(tls *libc.TLS, p uintptr, pCoord uintptr) (r int32) {
	var i Tu32
	_ = i
	i = *(*Tu32)(unsafe.Pointer(pCoord))
	**(**Tu8)(__ccgo_up(p)) = uint8(i >> libc.Int32FromInt32(24) & uint32(0xFF))
	**(**Tu8)(__ccgo_up(p + 1)) = uint8(i >> libc.Int32FromInt32(16) & uint32(0xFF))
	**(**Tu8)(__ccgo_up(p + 2)) = uint8(i >> libc.Int32FromInt32(8) & uint32(0xFF))
	**(**Tu8)(__ccgo_up(p + 3)) = uint8(i >> libc.Int32FromInt32(0) & uint32(0xFF))
	return int32(4)
}
