mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
src/{syscall, os}: add File.Stat, with smoke test
This is File.Stat from https://github.com/tinygo-org/tinygo/pull/2371, plus the windows bits, plus a smoke test more or less from upstream, all pulled together and rebased by dkegel-fastly.
This commit is contained in:
@@ -172,6 +172,15 @@ func Stat(path string, p *Stat_t) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func Fstat(fd int, p *Stat_t) (err error) {
|
||||
n := libc_fstat(int32(fd), unsafe.Pointer(p))
|
||||
|
||||
if n < 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Lstat(path string, p *Stat_t) (err error) {
|
||||
data := cstring(path)
|
||||
n := libc_lstat(&data[0], unsafe.Pointer(p))
|
||||
@@ -188,6 +197,10 @@ func Lstat(path string, p *Stat_t) (err error) {
|
||||
//export stat$INODE64
|
||||
func libc_stat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
|
||||
// int fstat(int fd, struct stat * buf);
|
||||
//export fstat$INODE64
|
||||
func libc_fstat(fd int32, ptr unsafe.Pointer) int32
|
||||
|
||||
// int lstat(const char *path, struct stat * buf);
|
||||
//export lstat$INODE64
|
||||
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
|
||||
@@ -212,6 +212,15 @@ func Stat(path string, p *Stat_t) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func Fstat(fd int, p *Stat_t) (err error) {
|
||||
n := libc_fstat(int32(fd), unsafe.Pointer(p))
|
||||
|
||||
if n < 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Lstat(path string, p *Stat_t) (err error) {
|
||||
data := cstring(path)
|
||||
n := libc_lstat(&data[0], unsafe.Pointer(p))
|
||||
@@ -225,6 +234,10 @@ func Lstat(path string, p *Stat_t) (err error) {
|
||||
//export stat
|
||||
func libc_stat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
|
||||
// int fstat(fd int, struct stat * buf);
|
||||
//export fstat
|
||||
func libc_fstat(fd int32, ptr unsafe.Pointer) int32
|
||||
|
||||
// int lstat(const char *path, struct stat * buf);
|
||||
//export lstat
|
||||
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
|
||||
Reference in New Issue
Block a user