Files
llgo/_demo/embed/write-esp32/main.go

32 lines
571 B
Go
Raw Normal View History

2025-09-02 20:06:48 +08:00
package main
2025-09-02 22:25:27 +08:00
import (
_ "unsafe"
2025-09-02 22:35:08 +08:00
2025-09-02 22:25:27 +08:00
"github.com/goplus/lib/c"
)
//go:linkname write C.write
2025-09-02 22:35:08 +08:00
func write(c.Int, *c.Char, c.SizeT) int
2025-09-02 20:06:48 +08:00
func main() {
buf := c.Malloc(6)
c.Memset(buf, 0, 6)
c.Strncpy((*c.Char)(buf), c.Str("abcde"), 5)
2025-09-02 22:35:08 +08:00
if c.Strcmp((*c.Char)(buf), c.Str("abcde")) == 0 {
write(1, c.Str("pass strcmp"), 11)
}
if byte(c.Index((*c.Char)(buf), 0)) == 'a' {
write(1, c.Str("pass index"), 10)
}
c.Memset(buf, c.Int('A'), 5)
if c.Strcmp((*c.Char)(buf), c.Str("AAAAA")) == 0 {
write(1, c.Str("pass memeset"), 11)
}
2025-09-02 20:06:48 +08:00
write(1, (*c.Char)(buf), 5)
}