You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -33,6 +33,7 @@ using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -89,6 +90,58 @@ namespace System
|
||||
*/
|
||||
private List<KeyValuePair<DateTime, TimeType>> transitions;
|
||||
|
||||
private static bool libcNotFound;
|
||||
|
||||
[DllImport ("libc")]
|
||||
private static extern int readlink (string path, byte[] buffer, int buflen);
|
||||
|
||||
private static string readlink (string path)
|
||||
{
|
||||
if (libcNotFound)
|
||||
return null;
|
||||
|
||||
byte[] buf = new byte [512];
|
||||
int ret;
|
||||
|
||||
try {
|
||||
ret = readlink (path, buf, buf.Length);
|
||||
} catch (DllNotFoundException e) {
|
||||
libcNotFound = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ret == -1) return null;
|
||||
char[] cbuf = new char [512];
|
||||
int chars = System.Text.Encoding.Default.GetChars (buf, 0, ret, cbuf, 0);
|
||||
return new String (cbuf, 0, chars);
|
||||
}
|
||||
|
||||
private static bool TryGetNameFromPath (string path, out string name)
|
||||
{
|
||||
name = null;
|
||||
var linkPath = readlink (path);
|
||||
if (linkPath != null)
|
||||
path = linkPath;
|
||||
|
||||
path = Path.GetFullPath (path);
|
||||
|
||||
if (string.IsNullOrEmpty (TimeZoneDirectory))
|
||||
return false;
|
||||
|
||||
var baseDir = TimeZoneDirectory;
|
||||
if (baseDir [baseDir.Length-1] != Path.DirectorySeparatorChar)
|
||||
baseDir += Path.DirectorySeparatorChar;
|
||||
|
||||
if (!path.StartsWith (baseDir, StringComparison.InvariantCulture))
|
||||
return false;
|
||||
|
||||
name = path.Substring (baseDir.Length);
|
||||
if (name == "localtime")
|
||||
name = "Local";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !MOBILE || MOBILE_STATIC
|
||||
static TimeZoneInfo CreateLocal ()
|
||||
{
|
||||
@@ -114,15 +167,22 @@ namespace System
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return FindSystemTimeZoneByFileName ("Local", "/etc/localtime");
|
||||
} catch (TimeZoneNotFoundException) {
|
||||
var tzFilePaths = new string [] {
|
||||
"/etc/localtime",
|
||||
Path.Combine (TimeZoneDirectory, "localtime")};
|
||||
|
||||
foreach (var tzFilePath in tzFilePaths) {
|
||||
try {
|
||||
return FindSystemTimeZoneByFileName ("Local", Path.Combine (TimeZoneDirectory, "localtime"));
|
||||
string tzName = null;
|
||||
if (!TryGetNameFromPath (tzFilePath, out tzName))
|
||||
tzName = "Local";
|
||||
return FindSystemTimeZoneByFileName (tzName, tzFilePath);
|
||||
} catch (TimeZoneNotFoundException) {
|
||||
return Utc;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return Utc;
|
||||
}
|
||||
|
||||
static TimeZoneInfo FindSystemTimeZoneByIdCore (string id)
|
||||
@@ -135,7 +195,7 @@ namespace System
|
||||
#endif
|
||||
}
|
||||
|
||||
static void GetSystemTimeZones (List<TimeZoneInfo> systemTimeZones)
|
||||
static void GetSystemTimeZonesCore (List<TimeZoneInfo> systemTimeZones)
|
||||
{
|
||||
#if !MOBILE_STATIC
|
||||
if (TimeZoneKey != null) {
|
||||
@@ -150,7 +210,7 @@ namespace System
|
||||
#endif
|
||||
|
||||
#if LIBC
|
||||
string[] continents = new string [] {"Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Brazil", "Canada", "Chile", "Europe", "Indian", "Mexico", "Mideast", "Pacific", "US"};
|
||||
string[] continents = new string [] {"Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Australia", "Brazil", "Canada", "Chile", "Europe", "Indian", "Mexico", "Mideast", "Pacific", "US"};
|
||||
foreach (string continent in continents) {
|
||||
try {
|
||||
foreach (string zonepath in Directory.GetFiles (Path.Combine (TimeZoneDirectory, continent))) {
|
||||
@@ -267,8 +327,13 @@ namespace System
|
||||
private static bool TryAddTicks (DateTime date, long ticks, out DateTime result, DateTimeKind kind = DateTimeKind.Unspecified)
|
||||
{
|
||||
var resultTicks = date.Ticks + ticks;
|
||||
if (resultTicks < DateTime.MinValue.Ticks || resultTicks > DateTime.MaxValue.Ticks) {
|
||||
result = default (DateTime);
|
||||
if (resultTicks < DateTime.MinValue.Ticks) {
|
||||
result = DateTime.SpecifyKind (DateTime.MinValue, kind);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (resultTicks > DateTime.MaxValue.Ticks) {
|
||||
result = DateTime.SpecifyKind (DateTime.MaxValue, kind);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -415,9 +480,7 @@ namespace System
|
||||
var utcOffset = sourceTimeZone.GetUtcOffset (dateTime, out isDst);
|
||||
|
||||
DateTime utcDateTime;
|
||||
if (!TryAddTicks (dateTime, -utcOffset.Ticks, out utcDateTime, DateTimeKind.Utc))
|
||||
return DateTime.SpecifyKind (DateTime.MinValue, DateTimeKind.Utc);
|
||||
|
||||
TryAddTicks (dateTime, -utcOffset.Ticks, out utcDateTime, DateTimeKind.Utc);
|
||||
return utcDateTime;
|
||||
}
|
||||
|
||||
@@ -651,7 +714,7 @@ namespace System
|
||||
{
|
||||
if (systemTimeZones == null) {
|
||||
var tz = new List<TimeZoneInfo> ();
|
||||
GetSystemTimeZones (tz);
|
||||
GetSystemTimeZonesCore (tz);
|
||||
Interlocked.CompareExchange (ref systemTimeZones, new ReadOnlyCollection<TimeZoneInfo> (tz), null);
|
||||
}
|
||||
|
||||
@@ -1175,7 +1238,7 @@ namespace System
|
||||
return (((i >> 24) & 0xff)
|
||||
| ((i >> 8) & 0xff00)
|
||||
| ((i << 8) & 0xff0000)
|
||||
| ((i << 24)));
|
||||
| (((i & 0xff) << 24)));
|
||||
}
|
||||
|
||||
static int ReadBigEndianInt32 (byte [] buffer, int start)
|
||||
|
||||
Reference in New Issue
Block a user