summaryrefslogtreecommitdiff
path: root/src/pkg/syscall
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/syscall')
-rw-r--r--src/pkg/syscall/syscall_mingw.go31
-rw-r--r--src/pkg/syscall/syscall_mingw_386.go2
-rw-r--r--src/pkg/syscall/zerrors_mingw_386.go1
-rw-r--r--src/pkg/syscall/zsyscall_mingw_386.go36
-rw-r--r--src/pkg/syscall/ztypes_mingw_386.go50
5 files changed, 86 insertions, 34 deletions
diff --git a/src/pkg/syscall/syscall_mingw.go b/src/pkg/syscall/syscall_mingw.go
index 97ddc6d65..c3f8b9fb7 100644
--- a/src/pkg/syscall/syscall_mingw.go
+++ b/src/pkg/syscall/syscall_mingw.go
@@ -57,8 +57,11 @@ func StringToUTF16(s string) []uint16 { return utf16.Encode([]int(s + "\x00")) }
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
// with a terminating NUL removed.
func UTF16ToString(s []uint16) string {
- if n := len(s); n > 0 && s[n-1] == 0 {
- s = s[0 : n-1]
+ for i, v := range s {
+ if v == 0 {
+ s = s[0:i]
+ break
+ }
}
return string(utf16.Decode(s))
}
@@ -105,6 +108,9 @@ func getSysProcAddr(m uint32, pname string) uintptr {
//sys SetFilePointer(handle int32, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, errno int) [failretval=0xffffffff]
//sys CloseHandle(handle int32) (ok bool, errno int)
//sys GetStdHandle(stdhandle int32) (handle int32, errno int) [failretval=-1]
+//sys FindFirstFile(name *uint16, data *Win32finddata) (handle int32, errno int) [failretval=-1] = FindFirstFileW
+//sys FindNextFile(handle int32, data *Win32finddata) (ok bool, errno int) = FindNextFileW
+//sys FindClose(handle int32) (ok bool, errno int)
// syscall interface implementation for other packages
@@ -117,7 +123,7 @@ func Errstr(errno int) string {
if err != 0 {
return "error " + str(errno) + " (FormatMessage failed with err=" + str(err) + ")"
}
- return UTF16ToString(b[0 : n-1])
+ return string(utf16.Decode(b[0 : n-1]))
}
func Exit(code int) { ExitProcess(uint32(code)) }
@@ -253,20 +259,31 @@ func getStdHandle(h int32) (fd int) {
return int(r)
}
+func Stat(path string, stat *Stat_t) (errno int) {
+ h, e := FindFirstFile(StringToUTF16Ptr(path), &stat.Windata)
+ if e != 0 {
+ return e
+ }
+ defer FindClose(h)
+ stat.Mode = 0
+ return 0
+}
+
+func Lstat(path string, stat *Stat_t) (errno int) {
+ // no links on windows, just call Stat
+ return Stat(path, stat)
+}
+
// TODO(brainman): fix all needed for os
const (
SIGTRAP = 5
)
-func Getdents(fd int, buf []byte) (n int, errno int) { return 0, EMINGW }
-
func Getpid() (pid int) { return -1 }
func Getppid() (ppid int) { return -1 }
func Mkdir(path string, mode int) (errno int) { return EMINGW }
-func Lstat(path string, stat *Stat_t) (errno int) { return EMINGW }
-func Stat(path string, stat *Stat_t) (errno int) { return EMINGW }
func Fstat(fd int, stat *Stat_t) (errno int) { return EMINGW }
func Chdir(path string) (errno int) { return EMINGW }
func Fchdir(fd int) (errno int) { return EMINGW }
diff --git a/src/pkg/syscall/syscall_mingw_386.go b/src/pkg/syscall/syscall_mingw_386.go
index 0368620cc..1ce025b31 100644
--- a/src/pkg/syscall/syscall_mingw_386.go
+++ b/src/pkg/syscall/syscall_mingw_386.go
@@ -4,6 +4,4 @@
package syscall
-// TODO(brainman): check Getpagesize
-
func Getpagesize() int { return 4096 }
diff --git a/src/pkg/syscall/zerrors_mingw_386.go b/src/pkg/syscall/zerrors_mingw_386.go
index d99aa2221..707e9b8a7 100644
--- a/src/pkg/syscall/zerrors_mingw_386.go
+++ b/src/pkg/syscall/zerrors_mingw_386.go
@@ -7,6 +7,7 @@ package syscall
const (
ERROR_FILE_NOT_FOUND = 2
+ ERROR_NO_MORE_FILES = 18
ERROR_INSUFFICIENT_BUFFER = 122
ERROR_MOD_NOT_FOUND = 126
ERROR_PROC_NOT_FOUND = 127
diff --git a/src/pkg/syscall/zsyscall_mingw_386.go b/src/pkg/syscall/zsyscall_mingw_386.go
index c01f40e7d..185180a86 100644
--- a/src/pkg/syscall/zsyscall_mingw_386.go
+++ b/src/pkg/syscall/zsyscall_mingw_386.go
@@ -20,6 +20,9 @@ var (
procSetFilePointer = getSysProcAddr(modKERNEL32, "SetFilePointer")
procCloseHandle = getSysProcAddr(modKERNEL32, "CloseHandle")
procGetStdHandle = getSysProcAddr(modKERNEL32, "GetStdHandle")
+ procFindFirstFileW = getSysProcAddr(modKERNEL32, "FindFirstFileW")
+ procFindNextFileW = getSysProcAddr(modKERNEL32, "FindNextFileW")
+ procFindClose = getSysProcAddr(modKERNEL32, "FindClose")
)
func GetLastError() (lasterrno int) {
@@ -165,3 +168,36 @@ func GetStdHandle(stdhandle int32) (handle int32, errno int) {
}
return
}
+
+func FindFirstFile(name *uint16, data *Win32finddata) (handle int32, errno int) {
+ r0, _, e1 := Syscall(procFindFirstFileW, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
+ handle = int32(r0)
+ if handle == -1 {
+ errno = int(e1)
+ } else {
+ errno = 0
+ }
+ return
+}
+
+func FindNextFile(handle int32, data *Win32finddata) (ok bool, errno int) {
+ r0, _, e1 := Syscall(procFindNextFileW, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
+ ok = bool(r0 != 0)
+ if !ok {
+ errno = int(e1)
+ } else {
+ errno = 0
+ }
+ return
+}
+
+func FindClose(handle int32) (ok bool, errno int) {
+ r0, _, e1 := Syscall(procFindClose, uintptr(handle), 0, 0)
+ ok = bool(r0 != 0)
+ if !ok {
+ errno = int(e1)
+ } else {
+ errno = 0
+ }
+ return
+}
diff --git a/src/pkg/syscall/ztypes_mingw_386.go b/src/pkg/syscall/ztypes_mingw_386.go
index 93364e44d..c683c6ed5 100644
--- a/src/pkg/syscall/ztypes_mingw_386.go
+++ b/src/pkg/syscall/ztypes_mingw_386.go
@@ -78,6 +78,8 @@ const (
FORMAT_MESSAGE_FROM_SYSTEM = 4096
FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192
FORMAT_MESSAGE_MAX_WIDTH_MASK = 255
+
+ MAX_PATH = 260
)
// Types
@@ -103,6 +105,29 @@ type Overlapped struct {
HEvent *byte
}
+type Filetime struct {
+ LowDateTime uint32
+ HighDateTime uint32
+}
+
+type Win32finddata struct {
+ FileAttributes uint32
+ CreationTime Filetime
+ LastAccessTime Filetime
+ LastWriteTime Filetime
+ FileSizeHigh uint32
+ FileSizeLow uint32
+ Reserved0 uint32
+ Reserved1 uint32
+ FileName [MAX_PATH - 1]uint16
+ AlternateFileName [13]uint16
+}
+
+type Stat_t struct {
+ Windata Win32finddata
+ Mode uint32
+}
+
// TODO(brainman): fix all needed for os
const (
@@ -135,28 +160,3 @@ const (
S_IWUSR = 0x80
S_IXUSR = 0x40
)
-
-type Stat_t struct {
- Dev int64
- Ino uint32
- Mode uint32
- Nlink uint32
- Uid uint32
- Gid uint32
- __padding int32
- Rdev int64
- Size int32
- Blksize int32
- Blocks int32
- Atime int32
- Mtime int32
- Ctime int32
-}
-
-type Dirent struct {
- Ino uint32
- Off int32
- Reclen uint16
- Name [256]int8
- Pad0 [2]byte
-}