OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _Platform { | 7 class _Platform { |
8 external static int _numberOfProcessors(); | 8 external static int _numberOfProcessors(); |
9 external static String _pathSeparator(); | 9 external static String _pathSeparator(); |
10 external static String _operatingSystem(); | 10 external static String _operatingSystem(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 static List<String> get executableArguments => _executableArguments(); | 52 static List<String> get executableArguments => _executableArguments(); |
53 | 53 |
54 static Map<String, String> get environment { | 54 static Map<String, String> get environment { |
55 if (_environmentCache == null) { | 55 if (_environmentCache == null) { |
56 var env = _environment(); | 56 var env = _environment(); |
57 if (env is !OSError) { | 57 if (env is !OSError) { |
58 var isWindows = operatingSystem == 'windows'; | 58 var isWindows = operatingSystem == 'windows'; |
59 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); | 59 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); |
60 for (var str in env) { | 60 for (var str in env) { |
61 // When running on Windows through cmd.exe there are strange | 61 // When running on Windows through cmd.exe there are |
62 // environment variables that are used to record the current | 62 // entries which starts with '='. In CMD scripting, |
63 // working directory for each drive and the exit code for the | 63 // variables are "dynamic" environment variables which change |
64 // last command. As an example: '=A:=A:\subdir' records the | 64 // automatically. The values of the ones starting with "=" are |
65 // current working directory on the 'A' drive. In order to | 65 // reified in the environment string of a new program (but, e.g., |
66 // handle these correctly we search for a second occurrence of | 66 // __CD__ isn't). |
67 // of '=' in the string if the first occurrence is at index 0. | 67 // |
| 68 // One example are the use of the environment to communicate the |
| 69 // current working directory for each drive and the exit code for the |
| 70 // last command. E.g. the entry '=A:=A:\subdir' records the current |
| 71 // working directory on the 'A' drive. |
| 72 // |
| 73 // On Mac OS an entry of just '=' has been seen. |
| 74 // |
| 75 // Entries starting with '=' are ignored. |
| 76 // |
| 77 // Entries with no '=' should not happen. If it should happen, |
| 78 // the entry is ignored. |
68 var equalsIndex = str.indexOf('='); | 79 var equalsIndex = str.indexOf('='); |
69 if (equalsIndex == 0) { | 80 if (equalsIndex > 0) { |
70 equalsIndex = str.indexOf('=', 1); | 81 result[str.substring(0, equalsIndex)] = |
| 82 str.substring(equalsIndex + 1); |
71 } | 83 } |
72 assert(equalsIndex != -1); | |
73 result[str.substring(0, equalsIndex)] = | |
74 str.substring(equalsIndex + 1); | |
75 } | 84 } |
76 _environmentCache = new UnmodifiableMapView<String, String>(result); | 85 _environmentCache = new UnmodifiableMapView<String, String>(result); |
77 } else { | 86 } else { |
78 _environmentCache = env; | 87 _environmentCache = env; |
79 } | 88 } |
80 } | 89 } |
81 | 90 |
82 if (_environmentCache is OSError) { | 91 if (_environmentCache is OSError) { |
83 throw _environmentCache; | 92 throw _environmentCache; |
84 } else { | 93 } else { |
(...skipping 24 matching lines...) Expand all Loading... |
109 V remove(String key) => _map.remove(key.toUpperCase()); | 118 V remove(String key) => _map.remove(key.toUpperCase()); |
110 void clear() => _map.clear(); | 119 void clear() => _map.clear(); |
111 void forEach(void f(String key, V value)) => _map.forEach(f); | 120 void forEach(void f(String key, V value)) => _map.forEach(f); |
112 Iterable<String> get keys => _map.keys; | 121 Iterable<String> get keys => _map.keys; |
113 Iterable<V> get values => _map.values; | 122 Iterable<V> get values => _map.values; |
114 int get length => _map.length; | 123 int get length => _map.length; |
115 bool get isEmpty => _map.isEmpty; | 124 bool get isEmpty => _map.isEmpty; |
116 bool get isNotEmpty => _map.isNotEmpty; | 125 bool get isNotEmpty => _map.isNotEmpty; |
117 String toString() => _map.toString(); | 126 String toString() => _map.toString(); |
118 } | 127 } |
OLD | NEW |