os: pull in os.Rename and some of its tests from upstream

Skip part of the test on Windows because of https://github.com/tinygo-org/tinygo/issues/2480

TODO: fix 2480 and unskip test
TODO: pull in rest of upstream tests, fix problems they find

Requested in https://github.com/tinygo-org/tinygo/issues/2109
This commit is contained in:
Dan Kegel
2022-01-03 10:52:41 -08:00
committed by Ron Evans
parent 72e15af1fa
commit 29f7ebc63e
5 changed files with 127 additions and 1 deletions
+14
View File
@@ -95,6 +95,16 @@ func Rmdir(path string) (err error) {
return
}
func Rename(from, to string) (err error) {
fromdata := cstring(from)
todata := cstring(to)
fail := int(libc_rename(&fromdata[0], &todata[0]))
if fail < 0 {
err = getErrno()
}
return
}
func Unlink(path string) (err error) {
data := cstring(path)
fail := int(libc_unlink(&data[0]))
@@ -270,6 +280,10 @@ func libc_mkdir(pathname *byte, mode uint32) int32
//export rmdir
func libc_rmdir(pathname *byte) int32
// int rename(const char *from, *to);
//export rename
func libc_rename(from, too *byte) int32
// int unlink(const char *pathname);
//export unlink
func libc_unlink(pathname *byte) int32