From 038fe8cfeab955abc8b24311757f48d2073ac440 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 18 Mar 2016 11:50:19 -0700 Subject: [PATCH] Replace execdrivers with containerd implementation Signed-off-by: Tonis Tiigi Signed-off-by: Kenfe-Mickael Laventure Signed-off-by: Anusha Ragunathan --- system/syscall_unix.go | 6 ++++++ system/syscall_windows.go | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/system/syscall_unix.go b/system/syscall_unix.go index f1497c5..3ae9128 100644 --- a/system/syscall_unix.go +++ b/system/syscall_unix.go @@ -9,3 +9,9 @@ import "syscall" func Unmount(dest string) error { return syscall.Unmount(dest, 0) } + +// CommandLineToArgv should not be used on Unix. +// It simply returns commandLine in the only element in the returned array. +func CommandLineToArgv(commandLine string) ([]string, error) { + return []string{commandLine}, nil +} diff --git a/system/syscall_windows.go b/system/syscall_windows.go index 273aa23..061e220 100644 --- a/system/syscall_windows.go +++ b/system/syscall_windows.go @@ -3,6 +3,7 @@ package system import ( "fmt" "syscall" + "unsafe" ) // OSVersion is a wrapper for Windows version information @@ -34,3 +35,26 @@ func GetOSVersion() (OSVersion, error) { func Unmount(dest string) error { return nil } + +// CommandLineToArgv wraps the Windows syscall to turn a commandline into an argument array. +func CommandLineToArgv(commandLine string) ([]string, error) { + var argc int32 + + argsPtr, err := syscall.UTF16PtrFromString(commandLine) + if err != nil { + return nil, err + } + + argv, err := syscall.CommandLineToArgv(argsPtr, &argc) + if err != nil { + return nil, err + } + defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv)))) + + newArgs := make([]string, argc) + for i, v := range (*argv)[:argc] { + newArgs[i] = string(syscall.UTF16ToString((*v)[:])) + } + + return newArgs, nil +}