// Non-generated exports
//
+ [DllImport (LIB, EntryPoint="Mono_Posix_FromRealTimeSignum")]
+ private static extern int FromRealTimeSignum (Int32 offset, out Int32 rval);
+
+ // convert a realtime signal to os signal
+ public static int FromRealTimeSignum (RealTimeSignum sig)
+ {
+ int sigNum;
+ if (FromRealTimeSignum (sig.Offset, out sigNum) == -1)
+ ThrowArgumentException (sig.Offset);
+ return sigNum;
+ }
+
+ // convert an offset to an rt signum
+ public static RealTimeSignum ToRealTimeSignum (int offset)
+ {
+ return new RealTimeSignum (offset);
+ }
+
// convert from octal representation.
public static FilePermissions FromOctalPermissionString (string value)
{
return '-';
}
+ public static readonly DateTime UnixEpoch =
+ new DateTime (year:1970, month:1, day:1, hour:0, minute:0, second:0, kind:DateTimeKind.Utc);
public static readonly DateTime LocalUnixEpoch =
new DateTime (1970, 1, 1);
public static readonly TimeSpan LocalUtcOffset =
return FromTimeT (time);
}
+ public static DateTime ToDateTime (long time, long nanoTime)
+ {
+ return FromTimeT (time).AddMilliseconds (nanoTime / 1000);
+ }
+
public static long FromDateTime (DateTime time)
{
return ToTimeT (time);
public static DateTime FromTimeT (long time)
{
- DateTime r = LocalUnixEpoch.AddSeconds ((double) time +
- LocalUtcOffset.TotalSeconds);
- return r;
+ return UnixEpoch.AddSeconds (time).ToLocalTime ();
}
public static long ToTimeT (DateTime time)
{
- TimeSpan unixTime = time.Subtract (LocalUnixEpoch) - LocalUtcOffset;
- return (long) unixTime.TotalSeconds;
+ if (time.Kind == DateTimeKind.Unspecified)
+ throw new ArgumentException ("DateTimeKind.Unspecified is not supported. Use Local or Utc times.", "time");
+
+ if (time.Kind == DateTimeKind.Local)
+ time = time.ToUniversalTime ();
+
+ return (long) (time - UnixEpoch).TotalSeconds;
}
public static OpenFlags ToOpenFlags (FileMode mode, FileAccess access)
throw new ArgumentException (fopen_mode);
return fopen_mode;
}
+
+ [DllImport (LIB, EntryPoint="Mono_Posix_FromStat")]
+ private static extern int FromStat (ref Stat source, IntPtr destination);
+
+ public static bool TryCopy (ref Stat source, IntPtr destination)
+ {
+ return FromStat (ref source, destination) == 0;
+ }
+
+ [DllImport (LIB, EntryPoint="Mono_Posix_ToStat")]
+ private static extern int ToStat (IntPtr source, out Stat destination);
+
+ public static bool TryCopy (IntPtr source, out Stat destination)
+ {
+ return ToStat (source, out destination) == 0;
+ }
+
+ [DllImport (LIB, EntryPoint="Mono_Posix_FromStatvfs")]
+ private static extern int FromStatvfs (ref Statvfs source, IntPtr destination);
+
+ public static bool TryCopy (ref Statvfs source, IntPtr destination)
+ {
+ return FromStatvfs (ref source, destination) == 0;
+ }
+
+ [DllImport (LIB, EntryPoint="Mono_Posix_ToStatvfs")]
+ private static extern int ToStatvfs (IntPtr source, out Statvfs destination);
+
+ public static bool TryCopy (IntPtr source, out Statvfs destination)
+ {
+ return ToStatvfs (source, out destination) == 0;
+ }
}
}