// Only for use by ProcessImpl.start() internal String ToEnvironmentBlock() { // Sort Unicode-case-insensitively by name List <Map_Entry <String, String> > list = new List <Map_Entry <String, String> >(this.EntrySet()); list.Sort(EntryComparator); StringBuilder sb = new StringBuilder(this.Size() * 30); int cmp = -1; // Some versions of MSVCRT.DLL require SystemRoot to be set. // So, we make sure that it is always set, even if not provided // by the caller. const String SYSTEMROOT = "SystemRoot"; foreach (Map_Entry <String, String> e in list) { String key = e.Key; String value = e.Value; if (cmp < 0 && (cmp = NameComparator.Compare(key, SYSTEMROOT)) > 0) { // Not set, so add it here AddToEnvIfSet(sb, SYSTEMROOT); } AddToEnv(sb, key, value); } if (cmp < 0) { // Got to end of list and still not found AddToEnvIfSet(sb, SYSTEMROOT); } if (sb.Length() == 0) { // Environment was empty and SystemRoot not set in parent sb.Append('\u0000'); } // Block is double NUL terminated sb.Append('\u0000'); return(sb.ToString()); }
public int Compare(Map_Entry <String, String> e1, Map_Entry <String, String> e2) { return(NameComparator.Compare(e1.Key, e2.Key)); }