aboutsummaryrefslogtreecommitdiff
path: root/internal/testfixture/main.go
blob: 02acb67a3a55cc6f6bf3985aeada3319e2d681c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2020 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package testfixture

import (
	"fmt"
	"os"
	"unsafe"

	"modernc.org/crt/v3"
)

func Main() {
	crt.Watch(fmt.Sprint(os.Args))
	tls := crt.NewTLS()
	argv := crt.Xcalloc(tls, crt.Size_t(len(os.Args)+1), crt.Size_t(unsafe.Sizeof(uintptr(0))))
	a := []uintptr{argv}
	p := argv
	for _, v := range os.Args {
		s := crt.Xcalloc(tls, crt.Size_t(len(v)+1), 1)
		a = append(a, s)
		copy((*(*[1 << 20]byte)(unsafe.Pointer(s)))[:], v)
		*(*uintptr)(unsafe.Pointer(p)) = s
		p += unsafe.Sizeof(uintptr(0))
	}
	crt.SetEnviron(os.Environ())
	rc := main(tls, int32(len(os.Args)), argv)
	for _, p := range a {
		crt.Xfree(tls, p)
	}
	crt.Xexit(tls, rc)
}