os: implement Getwd

This commit is contained in:
Federico G. Schwindt
2021-10-04 23:14:09 +01:00
committed by GitHub
parent 98fbf7ff25
commit b1ec8eb2e0
5 changed files with 47 additions and 2 deletions
+25
View File
@@ -0,0 +1,25 @@
// +build !baremetal,!wasi,!wasm
// This file assumes there is a libc available that runs on a real operating
// system.
package syscall
const pathMax = 1024
func Getwd() (string, error) {
var buf [pathMax]byte
s := libc_getcwd(&buf[0], uint(len(buf)))
if s == nil {
return "", getErrno()
}
n := clen(buf[:])
if n < 1 {
return "", EINVAL
}
return string(buf[:n]), nil
}
// char *getcwd(char *buf, size_t size)
//export getcwd
func libc_getcwd(buf *byte, size uint) *byte