File: env_tomap_windows.go

package info (click to toggle)
golang-github-caarlos0-env 11.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 240 kB
  • sloc: makefile: 29
file content (29 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (3)
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
//go:build windows

package env

import "strings"

func toMap(env []string) map[string]string {
	r := map[string]string{}
	for _, e := range env {
		p := strings.SplitN(e, "=", 2)

		// On Windows, environment variables can start with '='. If so, Split at next character.
		// See env_windows.go in the Go source: https://github.com/golang/go/blob/master/src/syscall/env_windows.go#L58
		prefixEqualSign := false
		if len(e) > 0 && e[0] == '=' {
			e = e[1:]
			prefixEqualSign = true
		}
		p = strings.SplitN(e, "=", 2)
		if prefixEqualSign {
			p[0] = "=" + p[0]
		}

		if len(p) == 2 {
			r[p[0]] = p[1]
		}
	}
	return r
}