Remove some dead Unix code (#15221)
authorJustin Van Patten <jvp@justinvp.com>
Sun, 26 Nov 2017 14:45:40 +0000 (06:45 -0800)
committerJan Kotas <jkotas@microsoft.com>
Sun, 26 Nov 2017 14:45:40 +0000 (06:45 -0800)
Environment.ExpandEnvironmentVariables is only used by RegistryKey
inside corelib, which is only present on Windows. There's no need for a
Unix implementation.

src/mscorlib/src/System/Environment.cs

index 159444040193c17ff78e7a2fca4b1c642f72de3f..55ba52ce544ff033e78c6d468b2a46cdd8280a52 100644 (file)
@@ -115,6 +115,8 @@ namespace System
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
         public static extern void FailFast(String message, Exception exception);
 
+#if FEATURE_WIN32_REGISTRY
+        // This is only used by RegistryKey on Windows.
         public static String ExpandEnvironmentVariables(String name)
         {
             if (name == null)
@@ -128,27 +130,6 @@ namespace System
             int currentSize = 100;
             StringBuilder blob = new StringBuilder(currentSize); // A somewhat reasonable default size
 
-#if PLATFORM_UNIX // Win32Native.ExpandEnvironmentStrings isn't available
-            int lastPos = 0, pos;
-            while (lastPos < name.Length && (pos = name.IndexOf('%', lastPos + 1)) >= 0)
-            {
-                if (name[lastPos] == '%')
-                {
-                    string key = name.Substring(lastPos + 1, pos - lastPos - 1);
-                    string value = Environment.GetEnvironmentVariable(key);
-                    if (value != null)
-                    {
-                        blob.Append(value);
-                        lastPos = pos + 1;
-                        continue;
-                    }
-                }
-                blob.Append(name.Substring(lastPos, pos - lastPos));
-                lastPos = pos;
-            }
-            blob.Append(name.Substring(lastPos));
-#else
-
             int size;
 
             blob.Length = 0;
@@ -166,10 +147,10 @@ namespace System
                 if (size == 0)
                     Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
             }
-#endif // PLATFORM_UNIX
 
             return blob.ToString();
         }
+#endif // FEATURE_WIN32_REGISTRY
 
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
         private static extern Int32 GetProcessorCount();