Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: sdk/lib/io/platform_impl.dart

Issue 831213002: Omit variables beginning with "=" from Windows environment. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update documentation. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/platform_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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();
11 external static _localHostname(); 11 external static _localHostname();
12 external static _executable(); 12 external static _executable();
13 /**
14 * Retrieve the entries of the process environment.
15 *
16 * The result is an [Iterable] of strings, where each string represents
17 * an environment entry.
18 *
19 * Environment entries should be strings containing
20 * a non-empty name and a value separated by a '=' character.
21 * The name does not contain a '=' character,
22 * so the name is everything up to the first '=' character.
23 * Values are everything after the first '=' charcacter.
24 * A value may contain further '=' characters, and it may be empty.
25 *
26 * Returns an [OSError] if retrieving the environment fails.
27 */
13 external static _environment(); 28 external static _environment();
14 external static List<String> _executableArguments(); 29 external static List<String> _executableArguments();
15 external static String _packageRoot(); 30 external static String _packageRoot();
16 external static String _version(); 31 external static String _version();
17 32
18 static String executable = _executable(); 33 static String executable = _executable();
19 static String packageRoot = _packageRoot(); 34 static String packageRoot = _packageRoot();
20 35
21 // Cache the OS environemnt. This can be an OSError instance if 36 // Cache the OS environemnt. This can be an OSError instance if
22 // retrieving the environment failed. 37 // retrieving the environment failed.
(...skipping 28 matching lines...) Expand all
51 66
52 static List<String> get executableArguments => _executableArguments(); 67 static List<String> get executableArguments => _executableArguments();
53 68
54 static Map<String, String> get environment { 69 static Map<String, String> get environment {
55 if (_environmentCache == null) { 70 if (_environmentCache == null) {
56 var env = _environment(); 71 var env = _environment();
57 if (env is !OSError) { 72 if (env is !OSError) {
58 var isWindows = operatingSystem == 'windows'; 73 var isWindows = operatingSystem == 'windows';
59 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); 74 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map();
60 for (var str in env) { 75 for (var str in env) {
61 // When running on Windows through cmd.exe there are 76 // The Strings returned by [_environment()] are expected to be
62 // entries which starts with '='. In CMD scripting, 77 // valid environment entries, but exceptions have been seen
63 // variables are "dynamic" environment variables which change 78 // (e.g., an entry of just '=' has been seen on OS/X).
64 // automatically. The values of the ones starting with "=" are 79 // Invalid entries (lines without a '=' or with an empty name)
65 // reified in the environment string of a new program (but, e.g., 80 // are discarded.
66 // __CD__ isn't).
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.
79 var equalsIndex = str.indexOf('='); 81 var equalsIndex = str.indexOf('=');
80 if (equalsIndex > 0) { 82 if (equalsIndex > 0) {
81 result[str.substring(0, equalsIndex)] = 83 result[str.substring(0, equalsIndex)] =
82 str.substring(equalsIndex + 1); 84 str.substring(equalsIndex + 1);
83 } 85 }
84 } 86 }
85 _environmentCache = new UnmodifiableMapView<String, String>(result); 87 _environmentCache = new UnmodifiableMapView<String, String>(result);
86 } else { 88 } else {
87 _environmentCache = env; 89 _environmentCache = env;
88 } 90 }
(...skipping 29 matching lines...) Expand all
118 V remove(String key) => _map.remove(key.toUpperCase()); 120 V remove(String key) => _map.remove(key.toUpperCase());
119 void clear() => _map.clear(); 121 void clear() => _map.clear();
120 void forEach(void f(String key, V value)) => _map.forEach(f); 122 void forEach(void f(String key, V value)) => _map.forEach(f);
121 Iterable<String> get keys => _map.keys; 123 Iterable<String> get keys => _map.keys;
122 Iterable<V> get values => _map.values; 124 Iterable<V> get values => _map.values;
123 int get length => _map.length; 125 int get length => _map.length;
124 bool get isEmpty => _map.isEmpty; 126 bool get isEmpty => _map.isEmpty;
125 bool get isNotEmpty => _map.isNotEmpty; 127 bool get isNotEmpty => _map.isNotEmpty;
126 String toString() => _map.toString(); 128 String toString() => _map.toString();
127 } 129 }
OLDNEW
« no previous file with comments | « runtime/bin/platform_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698