github.com/DQNEO/babygo@v0.0.3/src/syscall/syscall.go (about) 1 package syscall 2 3 import "unsafe" 4 5 const SYS_READ uintptr = 0 6 const SYS_WRITE uintptr = 1 7 const SYS_OPEN uintptr = 2 8 const SYS_CLOSE uintptr = 3 9 const SYS_GETDENTS64 uintptr = 217 10 11 func Read(fd int, buf []byte) (uintptr, int) { 12 p := &buf[0] 13 _cap := cap(buf) 14 var ret uintptr 15 ret = Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(_cap)) 16 return ret, 0 17 } 18 19 func Open(path string, mode int, perm int) (uintptr, int) { 20 buf := []byte(path) 21 buf = append(buf, 0) // add null terminator 22 p := &buf[0] 23 var fd uintptr 24 fd = Syscall(SYS_OPEN, uintptr(unsafe.Pointer(p)), uintptr(mode), uintptr(perm)) 25 return fd, 0 26 } 27 28 func Close(fd int) uintptr { 29 var e uintptr 30 e = Syscall(SYS_CLOSE, uintptr(fd), 0, 0) 31 return e 32 } 33 34 func Write(fd int, buf []byte) (uintptr, int) { 35 p := &buf[0] 36 _len := len(buf) 37 var ret uintptr 38 ret = Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(_len)) 39 return ret, 0 40 } 41 42 func Getdents(fd int, buf []byte) (int, int) { 43 var _p0 unsafe.Pointer 44 _p0 = unsafe.Pointer(&buf[0]) 45 nread := Syscall(SYS_GETDENTS64, uintptr(fd), uintptr(_p0), uintptr(len(buf))) 46 return int(nread), 0 47 } 48 49 func Syscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr) uintptr