1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Fork, exec, wait, etc.
9 // EscapeArg rewrites command line argument s as prescribed
10 // in http://msdn.microsoft.com/en-us/library/ms880421.
11 // This function returns "" (2 double quotes) if s is empty.
12 // Alternatively, these transformations are done:
13 // - every back slash (\) is doubled, but only if immediately
14 // followed by double quote (");
15 // - every double quote (") is escaped by back slash (\);
16 // - finally, s is wrapped with double quotes (arg -> "arg"),
17 // but only if there is space or tab inside s.
18 func EscapeArg(s string) string {
24 for i := 0; i < len(s); i++ {
46 for i := 0; i < len(s); i++ {
55 for ; slashes > 0; slashes-- {
66 for ; slashes > 0; slashes-- {
76 func CloseOnExec(fd Handle) {
77 SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0)
80 // FullPath retrieves the full path of the specified file.
81 func FullPath(name string) (path string, err error) {
82 p, err := UTF16PtrFromString(name)
88 buf := make([]uint16, n)
89 n, err = GetFullPathName(p, uint32(len(buf)), &buf[0], nil)
93 if n <= uint32(len(buf)) {
94 return UTF16ToString(buf[:n]), nil