os: implement Getwd
Этот коммит содержится в:
родитель
98fbf7ff25
коммит
b1ec8eb2e0
5 изменённых файлов: 47 добавлений и 2 удалений
|
@ -196,9 +196,8 @@ func Lstat(name string) (FileInfo, error) {
|
||||||
return nil, &PathError{"lstat", name, ErrNotImplemented}
|
return nil, &PathError{"lstat", name, ErrNotImplemented}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getwd is a stub (for now), always returning an empty string
|
|
||||||
func Getwd() (string, error) {
|
func Getwd() (string, error) {
|
||||||
return "", nil
|
return syscall.Getwd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Readlink is a stub (for now), always returning the string it was given
|
// Readlink is a stub (for now), always returning the string it was given
|
||||||
|
|
10
src/syscall/file_emulated.go
Обычный файл
10
src/syscall/file_emulated.go
Обычный файл
|
@ -0,0 +1,10 @@
|
||||||
|
// +build baremetal wasi wasm
|
||||||
|
|
||||||
|
// This file emulates some file-related functions that are only available
|
||||||
|
// under a real operating system.
|
||||||
|
|
||||||
|
package syscall
|
||||||
|
|
||||||
|
func Getwd() (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
25
src/syscall/file_hosted.go
Обычный файл
25
src/syscall/file_hosted.go
Обычный файл
|
@ -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
|
|
@ -22,3 +22,13 @@ func uitoa(val uint) string {
|
||||||
buf[i] = byte(val + '0')
|
buf[i] = byte(val + '0')
|
||||||
return string(buf[i:])
|
return string(buf[i:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte.
|
||||||
|
func clen(n []byte) int {
|
||||||
|
for i := 0; i < len(n); i++ {
|
||||||
|
if n[i] == 0 {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(n)
|
||||||
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ const (
|
||||||
EEXIST Errno = 0x11
|
EEXIST Errno = 0x11
|
||||||
EINTR Errno = 0x4
|
EINTR Errno = 0x4
|
||||||
ENOTDIR Errno = 0x14
|
ENOTDIR Errno = 0x14
|
||||||
|
EINVAL Errno = 0x16
|
||||||
EMFILE Errno = 0x18
|
EMFILE Errno = 0x18
|
||||||
EAGAIN Errno = 0x23
|
EAGAIN Errno = 0x23
|
||||||
ETIMEDOUT Errno = 0x3c
|
ETIMEDOUT Errno = 0x3c
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче