func toLong(path string) (string, error) { p := syscall.StringToUTF16(path) b := p // GetLongPathName says we can reuse buffer n, err := syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) if err != nil { return "", err } if n > uint32(len(b)) { b = make([]uint16, n) n, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) if err != nil { return "", err } } b = b[:n] return syscall.UTF16ToString(b), nil }
// longPath is copied over from the symlink package. This should be removed // if we add it to gc or in some other convenience package func longPath(path string) ([]uint16, error) { pathp, err := syscall.UTF16FromString(path) if err != nil { return nil, err } longp := pathp n, err := syscall.GetLongPathName(&pathp[0], &longp[0], uint32(len(longp))) if err != nil { return nil, err } if n > uint32(len(longp)) { longp = make([]uint16, n) n, err = syscall.GetLongPathName(&pathp[0], &longp[0], uint32(len(longp))) if err != nil { return nil, err } } longp = longp[:n] return longp, nil }
func toLong(path string) (string, error) { p, err := syscall.UTF16FromString(path) if err != nil { return "", err } b := p // GetLongPathName says we can reuse buffer n := uint32(len(b)) for { n, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) if err != nil { return "", err } if n <= uint32(len(b)) { return syscall.UTF16ToString(b[:n]), nil } b = make([]uint16, n) } }