forked from iamacarpet/go-winpty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
winpty_amd64.go
60 lines (47 loc) · 1.48 KB
/
winpty_amd64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package winpty
import (
"fmt"
"syscall"
"unsafe"
)
func createAgentCfg(flags uint32) (uintptr, error) {
var errorPtr uintptr
defer winpty_error_free.Call(errorPtr)
agentCfg, _, _ := winpty_config_new.Call(uintptr(flags), uintptr(unsafe.Pointer(errorPtr)))
if agentCfg == uintptr(0) {
return 0, fmt.Errorf("Unable to create agent config, %s", GetErrorMessage(errorPtr))
}
return agentCfg, nil
}
func createSpawnCfg(flags uint32, appname, cmdline, cwd string, env []string) (uintptr, error) {
var errorPtr uintptr
defer winpty_error_free.Call(errorPtr)
cmdLineStr, err := syscall.UTF16PtrFromString(cmdline)
if err != nil {
return 0, fmt.Errorf("Failed to convert cmd to pointer.")
}
appNameStr, err := syscall.UTF16PtrFromString(appname)
if err != nil {
return 0, fmt.Errorf("Failed to convert app name to pointer.")
}
cwdStr, err := syscall.UTF16PtrFromString(cwd)
if err != nil {
return 0, fmt.Errorf("Failed to convert working directory to pointer.")
}
envStr, err := UTF16PtrFromStringArray(env)
if err != nil {
return 0, fmt.Errorf("Failed to convert cmd to pointer.")
}
spawnCfg, _, _ := winpty_spawn_config_new.Call(
uintptr(flags),
uintptr(unsafe.Pointer(appNameStr)),
uintptr(unsafe.Pointer(cmdLineStr)),
uintptr(unsafe.Pointer(cwdStr)),
uintptr(unsafe.Pointer(envStr)),
uintptr(unsafe.Pointer(errorPtr)),
)
if spawnCfg == uintptr(0) {
return 0, fmt.Errorf("Unable to create spawn config, %s", GetErrorMessage(errorPtr))
}
return spawnCfg, nil
}