Improved scanner
All checks were successful
/ test (push) Successful in 13s

This commit is contained in:
Eduard Urbach 2025-06-19 21:39:04 +02:00
parent adfcd4b60c
commit 9b51680af5
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
8 changed files with 202 additions and 0 deletions

69
src/global/global.go Normal file
View file

@ -0,0 +1,69 @@
package global
import (
"os"
"path/filepath"
"runtime/debug"
)
// Global variables that are useful in all packages.
var (
Executable string
Library string
Root string
WorkingDirectory string
)
// init is the very first thing that's executed.
// It disables the GC and initializes global variables.
func init() {
debug.SetGCPercent(-1)
var err error
Executable, err = os.Executable()
if err != nil {
panic(err)
}
Executable, err = filepath.EvalSymlinks(Executable)
if err != nil {
panic(err)
}
WorkingDirectory, err = os.Getwd()
if err != nil {
panic(err)
}
Root = filepath.Dir(Executable)
Library = filepath.Join(Root, "lib")
stat, err := os.Stat(Library)
if err != nil || !stat.IsDir() {
findLibrary()
}
}
// findLibrary tries to go up each directory from the working directory and check for the existence of a "lib" directory.
// This is needed for tests to work correctly.
func findLibrary() {
dir := WorkingDirectory
for {
Library = filepath.Join(dir, "lib")
stat, err := os.Stat(Library)
if err == nil && stat.IsDir() {
return
}
if dir == "/" {
panic("standard library not found")
}
dir = filepath.Dir(dir)
}
}