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

//go:build (linux && ppc64le) || (linux && s390x)

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

const __FP_FAST_FMAL = 1

// C documentation
//
//	/*
//	** Append a single path element to the DbPath under construction
//	*/
func _appendOnePathElement(tls *libc.TLS, pPath uintptr, zName uintptr, nName int32) {
	bp := tls.Alloc(4256)
	defer tls.Free(4256)
	var got Tssize_t
	var zIn, v2 uintptr
	var v1 int32
	var _ /* buf at bp+0 */ Tstat
	var _ /* zLnk at bp+144 */ [4098]uint8
	_, _, _, _ = got, zIn, v1, v2
	if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zName))) == int32('.') {
		if nName == int32(1) {
			return
		}
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zName + 1))) == int32('.') && nName == int32(2) {
			if (*TDbPath)(unsafe.Pointer(pPath)).FnUsed > int32(1) {
				for {
					v2 = pPath + 20
					*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
					v1 = *(*int32)(unsafe.Pointer(v2))
					if !(libc.Int32FromUint8(**(**uint8)(__ccgo_up((*TDbPath)(unsafe.Pointer(pPath)).FzOut + uintptr(v1)))) != int32('/')) {
						break
					}
				}
			}
			return
		}
	}
	if (*TDbPath)(unsafe.Pointer(pPath)).FnUsed+nName+int32(2) >= (*TDbPath)(unsafe.Pointer(pPath)).FnOut {
		(*TDbPath)(unsafe.Pointer(pPath)).Frc = int32(SQLITE_ERROR)
		return
	}
	v2 = pPath + 20
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	**(**uint8)(__ccgo_up((*TDbPath)(unsafe.Pointer(pPath)).FzOut + uintptr(v1))) = uint8('/')
	libc.Xmemcpy(tls, (*TDbPath)(unsafe.Pointer(pPath)).FzOut+uintptr((*TDbPath)(unsafe.Pointer(pPath)).FnUsed), zName, libc.Uint64FromInt32(nName))
	**(**int32)(__ccgo_up(pPath + 20)) += nName
	if (*TDbPath)(unsafe.Pointer(pPath)).Frc == SQLITE_OK {
		**(**uint8)(__ccgo_up((*TDbPath)(unsafe.Pointer(pPath)).FzOut + uintptr((*TDbPath)(unsafe.Pointer(pPath)).FnUsed))) = uint8(0)
		zIn = (*TDbPath)(unsafe.Pointer(pPath)).FzOut
		if (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(27)].FpCurrent})))(tls, zIn, bp) != 0 {
			if **(**int32)(__ccgo_up(libc.X__errno_location(tls))) != int32(ENOENT) {
				(*TDbPath)(unsafe.Pointer(pPath)).Frc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(47152)), __ccgo_ts+3740, zIn, int32(47152))
			}
		} else {
			if (**(**Tstat)(__ccgo_up(bp))).Fst_mode&uint32(S_IFMT) == uint32(S_IFLNK) {
				v2 = pPath + 4
				v1 = *(*int32)(unsafe.Pointer(v2))
				*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
				if v1 > int32(SQLITE_MAX_SYMLINK) {
					(*TDbPath)(unsafe.Pointer(pPath)).Frc = _sqlite3CantopenError(tls, int32(47158))
					return
				}
				got = (*(*func(*libc.TLS, uintptr, uintptr, Tsize_t) Tssize_t)(unsafe.Pointer(&struct{ uintptr }{_aSyscall[int32(26)].FpCurrent})))(tls, zIn, bp+144, libc.Uint64FromInt64(4098)-libc.Uint64FromInt32(2))
				if got <= 0 || got >= libc.Int64FromInt64(4098)-libc.Int64FromInt32(2) {
					(*TDbPath)(unsafe.Pointer(pPath)).Frc = _unixLogErrorAtLine(tls, _sqlite3CantopenError(tls, int32(47163)), __ccgo_ts+3731, zIn, int32(47163))
					return
				}
				(**(**[4098]uint8)(__ccgo_up(bp + 144)))[got] = uint8(0)
				if libc.Int32FromUint8((**(**[4098]uint8)(__ccgo_up(bp + 144)))[0]) == int32('/') {
					(*TDbPath)(unsafe.Pointer(pPath)).FnUsed = 0
				} else {
					**(**int32)(__ccgo_up(pPath + 20)) -= nName + int32(1)
				}
				_appendAllPathElements(tls, pPath, bp+144)
			}
		}
	}
}
