runtime/internal/clite/syscall: fix init

This commit is contained in:
visualfc
2025-05-16 12:44:29 +08:00
parent 9a16fff27e
commit ffc1f712a3
4 changed files with 37 additions and 11 deletions

View File

@@ -7,7 +7,6 @@
package syscall package syscall
import ( import (
"strings"
"structs" "structs"
"unsafe" "unsafe"
) )
@@ -297,11 +296,19 @@ func joinPath(dir, file string) string {
} }
func isAbs(path string) bool { func isAbs(path string) bool {
return strings.HasPrefix(path, "/") return hasPrefix(path, "/")
} }
func isDir(path string) bool { func isDir(path string) bool {
return strings.HasSuffix(path, "/") return hasSuffix(path, "/")
}
func hasPrefix(s, prefix string) bool {
return len(s) >= len(prefix) && s[:len(prefix)] == prefix
}
func hasSuffix(s, suffix string) bool {
return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
} }
type Stat_t struct { type Stat_t struct {

View File

@@ -24,7 +24,7 @@ import (
) )
const ( const (
LLGoPackage = "noinit" LLGoPackage = true
) )
var ( var (
@@ -74,3 +74,25 @@ func Kill(pid int, signum Signal) error {
func ProcExit(code int32) { func ProcExit(code int32) {
panic("not implemented") panic("not implemented")
} }
func _utoa(buf []byte, val uint64) []byte {
i := len(buf) - 1
for val >= 10 {
buf[i] = byte(val%10 + '0')
i--
val /= 10
}
buf[i] = byte(val + '0')
return buf[i:]
}
func utoa(val uint64) string {
return string(_utoa(make([]byte, 20), val))
}
func itoa(val int64) string {
if val < 0 {
return "-" + string(_utoa(make([]byte, 20), uint64(-val)))
}
return string(_utoa(make([]byte, 20), uint64(val)))
}

View File

@@ -2,8 +2,6 @@
package syscall package syscall
import "strconv"
type Errno uintptr type Errno uintptr
func (e Errno) Error() string { func (e Errno) Error() string {
@@ -13,7 +11,7 @@ func (e Errno) Error() string {
return s return s
} }
} }
return "errno " + strconv.Itoa(int(e)) return "errno " + utoa(uint64(e))
} }
func (e Errno) Is(target error) bool { func (e Errno) Is(target error) bool {
@@ -51,5 +49,5 @@ func (s Signal) String() string {
return str return str
} }
} }
return "signal " + strconv.Itoa(int(s)) return "signal " + itoa(int64(s))
} }

View File

@@ -5,7 +5,6 @@
package syscall package syscall
import ( import (
"strconv"
"unsafe" "unsafe"
) )
@@ -79,7 +78,7 @@ func (e Errno) Error() string {
return s return s
} }
} }
return "errno " + strconv.Itoa(int(e)) return "errno " + utoa(uint64(e))
} }
func (e Errno) Is(target error) bool { func (e Errno) Is(target error) bool {
@@ -209,7 +208,7 @@ func (s Signal) String() string {
case SIGSYS: case SIGSYS:
return "bad system call" return "bad system call"
default: default:
return "signal " + strconv.Itoa(int(s)) return "signal " + utoa(uint64(s))
} }
} }