From d5c948c0367c9459cee5a1918a62e517452e0b67 Mon Sep 17 00:00:00 2001 From: Dick Porter Date: Tue, 11 Dec 2001 16:59:43 +0000 Subject: [PATCH] 2001-12-11 Dick Porter * Linux.cs: IO implemented with file handles with internal calls, rather than casting file descriptors for C library p/invokes. Implemented Get/Set Creation/LastAccess/LastWrite TimeFile functions. 2001-12-11 Dick Porter * FileStream.cs: Use handles rather than casting file descriptors. Added Handle property. 2001-12-11 Dick Porter * DateTime.cs: Implemented FromFileTime() and ToFileTime() * Console.cs: Use handles rather than casting file descriptors 2001-12-11 Dick Porter * WaitHandle.cs: Implemented WaitAll(), WaitAny() and WaitOne() as internal calls. svn path=/trunk/mcs/; revision=1557 --- mcs/class/corlib/Linux/ChangeLog | 6 + mcs/class/corlib/Linux/Linux.cs | 1079 ++++++------ mcs/class/corlib/System.IO/ChangeLog | 4 + mcs/class/corlib/System.IO/FileAccess.cs | 2 +- mcs/class/corlib/System.IO/FileAttributes.cs | 4 +- mcs/class/corlib/System.IO/FileMode.cs | 2 +- mcs/class/corlib/System.IO/FileShare.cs | 2 +- mcs/class/corlib/System.IO/FileStream.cs | 57 +- mcs/class/corlib/System.IO/SeekOrigin.cs | 2 +- mcs/class/corlib/System.IO/Stream.cs | 413 ++--- mcs/class/corlib/System.Threading/ChangeLog | 5 + .../corlib/System.Threading/WaitHandle.cs | 49 +- mcs/class/corlib/System/ChangeLog | 6 + mcs/class/corlib/System/Console.cs | 16 +- mcs/class/corlib/System/DateTime.cs | 1476 +++++++++-------- 15 files changed, 1581 insertions(+), 1542 deletions(-) diff --git a/mcs/class/corlib/Linux/ChangeLog b/mcs/class/corlib/Linux/ChangeLog index c4c1346b4fc..01c46cc3430 100644 --- a/mcs/class/corlib/Linux/ChangeLog +++ b/mcs/class/corlib/Linux/ChangeLog @@ -1,3 +1,9 @@ +2001-12-11 Dick Porter + + * Linux.cs: IO implemented with file handles with internal calls, + rather than casting file descriptors for C library p/invokes. + Implemented Get/Set Creation/LastAccess/LastWrite TimeFile + functions. Wed Nov 14 16:30:27 CET 2001 Paolo Molaro diff --git a/mcs/class/corlib/Linux/Linux.cs b/mcs/class/corlib/Linux/Linux.cs index 3a0de812a11..f432c98484d 100644 --- a/mcs/class/corlib/Linux/Linux.cs +++ b/mcs/class/corlib/Linux/Linux.cs @@ -1,560 +1,531 @@ -/*--------------------------------------------------------------------- - - XX X XXX - XX XX - XXX XX XXX XXXXX XX - XX XXX XX XX XX - XX XX XX XX XXXXX XX - XX XX XX XX XX XX X XX - XXXX XX XX XXX XXXXXXX XXXX - XX - XXXXX - -Copyright (c) 2001 Intel Corporation. All Rights Reserved. - -CREATED: August 22, 2001 -OWNER: Scott D Smith, Joel Marcey -VERSION: 1.0 ----------------------------------------------------------------------*/ - -using System; -using System.Runtime.InteropServices; -using System.Text; -using System.IO; -using System.Collections; +/*--------------------------------------------------------------------- + + XX X XXX + XX XX + XXX XX XXX XXXXX XX + XX XXX XX XX XX + XX XX XX XX XXXXX XX + XX XX XX XX XX XX X XX + XXXX XX XX XXX XXXXXXX XXXX + XX + XXXXX + +Copyright (c) 2001 Intel Corporation. All Rights Reserved. + +CREATED: August 22, 2001 +OWNER: Scott D Smith, Joel Marcey +VERSION: 1.0 +---------------------------------------------------------------------*/ + +using System; +using System.Runtime.InteropServices; +using System.Text; +using System.IO; +using System.Collections; using System.Reflection; - -namespace System.PAL -{ - /// - /// Class that implements IOperatingSystem, providing the requested functionality through calls into APIs available in Linux - /// +using System.Runtime.CompilerServices; + +namespace System.PAL +{ + /// + /// Class that implements IOperatingSystem, providing the requested functionality through calls into APIs available in Linux + /// internal class OpSys - { - private Hashtable _environment = null; - - //---------------------------------- - // Class Constants - //---------------------------------- - private const int EOF = -1; // TODO: Linux: Is this true? - - - // For StdInputStream and StdOutputStream - private const int STDOUT = 1; // TODO: Linux: Is this true? - private const int STDIN = 0; // TODO: Linux: Is this true? - - - //---------------------------------- - // Class Fields - //---------------------------------- - - //---------------------------------- - // Class Constructor - //---------------------------------- - public OpSys() - { - } - - - //------------------------------------------------- - // Environment Services - //------------------------------------------------- - - public string NewLineSequence - { - get - { - return "\n"; - } - } - - public char DirectorySeparator - { - get - { - return '/'; - } - } - - public char AltDirectorySeparator - { - get - { - return '\\'; - } - } - - public char VolumeSeparator - { - get - { - return '/'; - } - } - - public char PathSeparator - { - get - { - return ':'; - } - } - - public char[] InvalidPathChars - { - get - { - return new char[] { '\0' }; - } - } - - public char[] DirVolSeparatorChars - { - get - { - return new char[] { this.DirectorySeparator, this.AltDirectorySeparator, this.VolumeSeparator}; - } - } - public char ExtensionCharacter - { - get - { - return '.'; - } - } - - public string GetEnvironmentVariable(string eVar) - { - return EnvironmentVariables[eVar].ToString(); - } - - public IDictionary EnvironmentVariables - { - get - { - if (_environment == null) { - IntPtr pp = _getEnviron(); // pointer to an array of char* - _environment = new Hashtable(); - - if (pp != IntPtr.Zero) { - IntPtr p; - bool done = false; - char[] delimiter = { '=' }; - - while (!done) - { - p = Marshal.ReadIntPtr(pp); - if (p != IntPtr.Zero) - { - string str = Marshal.PtrToStringAuto(p); - string[] ar = str.Split(delimiter, 2); - switch(ar.Length) - { - case 1: - _environment.Add(ar[0], ""); - break; - case 2: - _environment.Add(ar[0], ar[1]); - break; - default: - System.Diagnostics.Debug.Assert(false); // this shouldn't happen - break; - } - } - else - { - done = true; - } - } - } - } - return _environment; - } - } - - public string CommandLine - { - get - { - string path = Path.Combine(Path.Combine("/proc", _getPid().ToString()), "cmdline"); - StreamReader stream = File.OpenText(path); - string res = stream.ReadToEnd(); - stream.Close(); - return res; - } - } - - public string MachineName - { - get - { - return GetEnvironmentVariable("HOSTNAME"); - } - } - - public OperatingSystem OSVersion - { - get - { - return null; - } - } - - // System.Path services - - public string ChangeExtension(string path, string extension) - { - System.Diagnostics.Debug.WriteLine("Linux:ChangeExtension(System.String, System.String): Stub Method"); - return null; - } - - public string GetExtension(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetExtension(System.String): Stub Method"); - return null; - } - - public string GetFileName(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetFileName(System.String): Stub Method"); - return null; - } - - public string GetFileNameWithoutExtension(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetFileNameWithoutExtension(System.String): Stub Method"); - return null; - } - - public string GetFullPath(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetFullPath(System.String): Stub Method"); - return null; - } - - public string GetPathRoot(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetPathRoot(System.String): Stub Method"); - return null; - - } - - public string GetTempFileName() - { - System.Diagnostics.Debug.WriteLine("Linux:GetTempFileName(): Stub Method"); - return null; - } - - public string GetTempPath() - { - System.Diagnostics.Debug.WriteLine("Linux:GetTempPath(): Stub Method"); - return null; - } - - public bool HasExtension(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:HasExtension(System.String): Stub Method"); - return false; - } - - public bool IsPathRooted(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:IsPathRooted(System.String): Stub Method"); - return false; - } - - - - // System.Directory services - - public void DeleteDirectory(string path, bool recursive) - { - System.Diagnostics.Debug.WriteLine("Linux:DeleteDirectory(System.String, System.Boolean): Stub Method"); - } - - public bool ExistsDirectory(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:ExistsDirectory(System.String): Stub Method"); - return false; - } - - public DateTime GetCreationTimeDirectory(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetCreationTimeDirectory(System.String): Stub Method"); - return new DateTime(0); - } - + { + private Hashtable _environment = null; + + //---------------------------------- + // Class Constants + //---------------------------------- + private const int EOF = -1; // TODO: Linux: Is this true? + + + // For StdInputStream and StdOutputStream + private IntPtr Stdin; + private IntPtr Stdout; + private IntPtr Stderr; + + //---------------------------------- + // Class Fields + //---------------------------------- + + //---------------------------------- + // Class Constructor + //---------------------------------- + public OpSys() + { + Stdin=GetStdHandle(0); + Stdout=GetStdHandle(1); + Stderr=GetStdHandle(2); + } + + + //------------------------------------------------- + // Environment Services + //------------------------------------------------- + + public string NewLineSequence + { + get + { + return "\n"; + } + } + + public char DirectorySeparator + { + get + { + return '/'; + } + } + + public char AltDirectorySeparator + { + get + { + return '\\'; + } + } + + public char VolumeSeparator + { + get + { + return '/'; + } + } + + public char PathSeparator + { + get + { + return ':'; + } + } + + public char[] InvalidPathChars + { + get + { + return new char[] { '\0' }; + } + } + + public char[] DirVolSeparatorChars + { + get + { + return new char[] { this.DirectorySeparator, this.AltDirectorySeparator, this.VolumeSeparator}; + } + } + public char ExtensionCharacter + { + get + { + return '.'; + } + } + + public string GetEnvironmentVariable(string eVar) + { + return EnvironmentVariables[eVar].ToString(); + } + + public IDictionary EnvironmentVariables + { + get + { + if (_environment == null) { + IntPtr pp = _getEnviron(); // pointer to an array of char* + _environment = new Hashtable(); + + if (pp != IntPtr.Zero) { + IntPtr p; + bool done = false; + char[] delimiter = { '=' }; + + while (!done) + { + p = Marshal.ReadIntPtr(pp); + if (p != IntPtr.Zero) + { + string str = Marshal.PtrToStringAuto(p); + string[] ar = str.Split(delimiter, 2); + switch(ar.Length) + { + case 1: + _environment.Add(ar[0], ""); + break; + case 2: + _environment.Add(ar[0], ar[1]); + break; + default: + System.Diagnostics.Debug.Assert(false); // this shouldn't happen + break; + } + } + else + { + done = true; + } + } + } + } + return _environment; + } + } + + public string CommandLine + { + get + { + string path = Path.Combine(Path.Combine("/proc", _getPid().ToString()), "cmdline"); + StreamReader stream = File.OpenText(path); + string res = stream.ReadToEnd(); + stream.Close(); + return res; + } + } + + public string MachineName + { + get + { + return GetEnvironmentVariable("HOSTNAME"); + } + } + + public OperatingSystem OSVersion + { + get + { + return null; + } + } + + // System.Path services + + public string ChangeExtension(string path, string extension) + { + System.Diagnostics.Debug.WriteLine("Linux:ChangeExtension(System.String, System.String): Stub Method"); + return null; + } + + public string GetExtension(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetExtension(System.String): Stub Method"); + return null; + } + + public string GetFileName(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetFileName(System.String): Stub Method"); + return null; + } + + public string GetFileNameWithoutExtension(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetFileNameWithoutExtension(System.String): Stub Method"); + return null; + } + + public string GetFullPath(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetFullPath(System.String): Stub Method"); + return null; + } + + public string GetPathRoot(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetPathRoot(System.String): Stub Method"); + return null; + + } + + public string GetTempFileName() + { + System.Diagnostics.Debug.WriteLine("Linux:GetTempFileName(): Stub Method"); + return null; + } + + public string GetTempPath() + { + System.Diagnostics.Debug.WriteLine("Linux:GetTempPath(): Stub Method"); + return null; + } + + public bool HasExtension(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:HasExtension(System.String): Stub Method"); + return false; + } + + public bool IsPathRooted(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:IsPathRooted(System.String): Stub Method"); + return false; + } + + + + // System.Directory services + + public void DeleteDirectory(string path, bool recursive) + { + System.Diagnostics.Debug.WriteLine("Linux:DeleteDirectory(System.String, System.Boolean): Stub Method"); + } + + public bool ExistsDirectory(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:ExistsDirectory(System.String): Stub Method"); + return false; + } + + public DateTime GetCreationTimeDirectory(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetCreationTimeDirectory(System.String): Stub Method"); + return new DateTime(0); + } + [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] public extern string GetCurrentDirectory(); - public string[] GetDirectories(string path, string searchPattern) - { - System.Diagnostics.Debug.WriteLine("Linux:GetDirectories(System.String,System.String): Stub Method"); - return null; - } - - public string[] GetFiles(string path, string searchPattern) - { - System.Diagnostics.Debug.WriteLine("Linux:GetFiles(System.String, System.String): Stub Method"); - return null; - } - - public string[] GetFileSystemEntries(string path, string searchPattern) - { - System.Diagnostics.Debug.WriteLine("Linux:GetFileSystemEntries(System.String, System.String): Stub Method"); - return null; - } - - public DateTime GetLastAccessTimeDirectory(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetLastAccessTimeDirectory(System.String): Stub Method"); - return new DateTime(0); - } - - public DateTime GetLastWriteTimeDirectory(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetLastWriteTimeDirectory(System.String): Stub Method"); - return new DateTime(0); - } - - public void MoveDirectory(string sourceDirName, string destDirName) - { - System.Diagnostics.Debug.WriteLine("Linux:MoveDirectory(System.String, System.String): Stub Method"); - } - - public void SetCreationTimeDirectory(string path, DateTime creationTime) - { - System.Diagnostics.Debug.WriteLine("Linux:SetCreationTimeDirectory(System.String, System.DateTime): Stub Method"); - } - - public void SetCurrentDirectory(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:SetCurrentDirectory(System.String): Stub Method"); - } - - public void SetLastAccessTimeDirectory(string path, DateTime lastAccessTime) - { - System.Diagnostics.Debug.WriteLine("Linux:SetLastAccessTimeDirectory(System.String, System.DateTime): Stub Method"); - } - - public void SetLastWriteTimeDirectory(string path, DateTime lastWriteTime) - { - System.Diagnostics.Debug.WriteLine("Linux:SetLastWriteTimeDirectory(System.String, System.DateTime): Stub Method"); - } - - //----------------------------------- - // I/O Services - //----------------------------------- - - // For StdInputStream - public int ReadStdInput(byte[] buffer, int offset, int count) - { - return ReadFile(new IntPtr(STDIN), buffer, offset, count); - } - - // For StdOutputStream - public void FlushStdOutput(byte[] byteBuf) - { - FlushFile(new IntPtr(STDOUT), byteBuf); - } - - public unsafe int ReadFile(IntPtr handle, byte[] buffer, int offset, int count) - { - int res; - - fixed (void *p = &buffer [offset]) { - res = _read(handle, p, count); - } - - return res; - } - - public unsafe int WriteFile(IntPtr handle, byte[] buffer, int offset, int count) - { - int res; - - fixed (void *p = &buffer [offset]) { - res = _write(handle, p, count); - } - - return res; - } - - public int SetLengthFile(IntPtr handle, long length) - { - return _ftruncate (handle, (int)length); - } - - public void FlushFile(IntPtr handle, byte[] byteBuf) - { - WriteFile(handle, byteBuf, 0, byteBuf.Length); - } - - public IntPtr OpenFile(string path, FileMode mode, FileAccess access, FileShare share) - { - int flags = _getUnixFlags (mode, access); - - return _open (path, flags, 0x1a4); - } - - public void CloseFile(IntPtr handle) - { - _close (handle); - } - - public long SeekFile(IntPtr handle, long offset, SeekOrigin origin) - { - switch (origin) { - case SeekOrigin.End: - return _lseek (handle, (int)offset, SEEK_END); - case SeekOrigin.Current: - return _lseek (handle, (int)offset, SEEK_CUR); - default: - return _lseek (handle, (int)offset, SEEK_SET); - } - - } - - public IntPtr CreateFile(string path, FileMode mode, FileAccess access, FileShare share) - { - return OpenFile(path, FileMode.CreateNew, access, share); - } - - public void DeleteFile(string path) - { - _unlink(path); - } - - public bool ExistsFile(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:ExistsFile(System.String): Stub Method"); - return false; - } - - public DateTime GetCreationTimeFile(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetCreationTimeFile(System.String): Stub Method"); - return new DateTime(0); - } - - public DateTime GetLastAccessTimeFile(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetLastAccessTimeFile(System.String): Stub Method"); - return new DateTime(0); - } - - public DateTime GetLastWriteTimeFile(string path) - { - System.Diagnostics.Debug.WriteLine("Linux:GetLastWriteFile(System.String): Stub Method"); - return new DateTime(0); - } - - public void SetCreationTimeFile(string path, DateTime creationTime) - { - System.Diagnostics.Debug.WriteLine("Linux:SetCreationTimeFile(System.String, System.DateTime): Stub Method"); - } - - public void SetLastAccessTimeFile(string path, DateTime lastAccessTime) - { - System.Diagnostics.Debug.WriteLine("Linux:SetLastAccessTimeFile(System.String, System.DateTime): Stub Method"); - } - - public void SetLastWriteTimeFile(string path, DateTime lastWriteTime) - { - System.Diagnostics.Debug.WriteLine("Linux:SetCLastWriteTimeFile(System.String, System.DateTime): Stub Method"); - } - - - public long FileLength(string path) - { - return 0; - } - - public long FileLength(IntPtr handle) - { - return 0; - } - - // Private implementation details - [DllImport("monowrapper", EntryPoint="mono_wrapper_environ", CharSet=CharSet.Ansi)] - private unsafe static extern IntPtr _getEnviron(); - - [DllImport("libc", EntryPoint="getpid")] - private unsafe static extern int _getPid(); - - [DllImport("libc", EntryPoint="read", CharSet=CharSet.Ansi)] - private unsafe static extern int _read(IntPtr fd, void * buf, int count); - - [DllImport("libc", EntryPoint="write", CharSet=CharSet.Ansi)] - private unsafe static extern int _write(IntPtr fd, void * buf, int count); - - [DllImport("libc", EntryPoint="ftruncate", CharSet=CharSet.Ansi)] - private unsafe static extern int _ftruncate(IntPtr fd, int count); - - [DllImport("libc", EntryPoint="lseek", CharSet=CharSet.Ansi)] - private unsafe static extern int _lseek(IntPtr fd, int offset, int whence); - - [DllImport("libc", EntryPoint="fflush", CharSet=CharSet.Ansi)] - private unsafe static extern int _fflush(IntPtr fd); - - [DllImport("libc", EntryPoint="close", CharSet=CharSet.Ansi)] - private unsafe static extern int _close(IntPtr fd); - - [DllImport("libc", EntryPoint="open", CharSet=CharSet.Ansi)] - private unsafe static extern IntPtr _open(string path, int flags, int mode); - - [DllImport("libc", EntryPoint="unlink", CharSet=CharSet.Ansi)] - private unsafe static extern int _unlink(string path); - - private const int O_RDONLY = 0x00000000; - private const int O_WRONLY = 0x00000001; - private const int O_RDWR = 0x00000002; - private const int O_CREAT = 0x00000040; - private const int O_EXCL = 0x00000080; - private const int O_TRUNC = 0x00000200; - private const int O_APPEND = 0x00000400; - - private const int SEEK_SET = 0; - private const int SEEK_CUR = 1; - private const int SEEK_END = 2; - - private int _getUnixFlags (FileMode mode, FileAccess access) - { - int flags = 0; - switch (access) { - case FileAccess.Read: - flags = O_RDONLY; - break; - case FileAccess.Write: - flags = O_WRONLY; - break; - case FileAccess.ReadWrite: - flags = O_RDWR; - break; - } - - switch (mode) { - case FileMode.Append: - flags |= O_APPEND; - break; - case FileMode.Create: - flags |= O_CREAT; - break; - case FileMode.CreateNew: - flags |= O_CREAT | O_EXCL; - break; - case FileMode.Open: - break; - case FileMode.OpenOrCreate: - flags |= O_CREAT; - break; - case FileMode.Truncate: - flags |= O_TRUNC; - break; - } - - return flags; - } + public string[] GetDirectories(string path, string searchPattern) + { + System.Diagnostics.Debug.WriteLine("Linux:GetDirectories(System.String,System.String): Stub Method"); + return null; + } + + public string[] GetFiles(string path, string searchPattern) + { + System.Diagnostics.Debug.WriteLine("Linux:GetFiles(System.String, System.String): Stub Method"); + return null; + } + + public string[] GetFileSystemEntries(string path, string searchPattern) + { + System.Diagnostics.Debug.WriteLine("Linux:GetFileSystemEntries(System.String, System.String): Stub Method"); + return null; + } + + public DateTime GetLastAccessTimeDirectory(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetLastAccessTimeDirectory(System.String): Stub Method"); + return new DateTime(0); + } + + public DateTime GetLastWriteTimeDirectory(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:GetLastWriteTimeDirectory(System.String): Stub Method"); + return new DateTime(0); + } + + public void MoveDirectory(string sourceDirName, string destDirName) + { + System.Diagnostics.Debug.WriteLine("Linux:MoveDirectory(System.String, System.String): Stub Method"); + } + + public void SetCreationTimeDirectory(string path, DateTime creationTime) + { + System.Diagnostics.Debug.WriteLine("Linux:SetCreationTimeDirectory(System.String, System.DateTime): Stub Method"); + } + + public void SetCurrentDirectory(string path) + { + System.Diagnostics.Debug.WriteLine("Linux:SetCurrentDirectory(System.String): Stub Method"); + } + + public void SetLastAccessTimeDirectory(string path, DateTime lastAccessTime) + { + System.Diagnostics.Debug.WriteLine("Linux:SetLastAccessTimeDirectory(System.String, System.DateTime): Stub Method"); + } + + public void SetLastWriteTimeDirectory(string path, DateTime lastWriteTime) + { + System.Diagnostics.Debug.WriteLine("Linux:SetLastWriteTimeDirectory(System.String, System.DateTime): Stub Method"); + } + + //----------------------------------- + // I/O Services + //----------------------------------- + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + private extern IntPtr GetStdHandle(int fd); + + public IntPtr StdinHandle { + get { + return(Stdin); + } + } + + public IntPtr StdoutHandle { + get { + return(Stdout); + } + } + + public IntPtr StderrHandle { + get { + return(Stderr); + } + } + + + // For StdInputStream + public int ReadStdInput(byte[] buffer, int offset, int count) + { + return ReadFile(StdinHandle, buffer, offset, count); + } + + // For StdOutputStream + public void FlushStdOutput(byte[] byteBuf) + { + FlushFile(StdoutHandle, byteBuf); + } + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern int ReadFile(IntPtr handle, byte[] buffer, int offset, int count); + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern int WriteFile(IntPtr handle, byte[] buffer, int offset, int count); + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern int SetLengthFile(IntPtr handle, long length); + + public void FlushFile(IntPtr handle, byte[] byteBuf) + { + WriteFile(handle, byteBuf, 0, byteBuf.Length); + } + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern IntPtr OpenFile(String path, FileMode mode, FileAccess access, FileShare share); + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern void CloseFile(IntPtr handle); + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern long SeekFile(IntPtr handle, long offset, SeekOrigin origin); + + public IntPtr CreateFile(string path, FileMode mode, FileAccess access, FileShare share) + { + return OpenFile(path, FileMode.CreateNew, access, share); + } + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern void DeleteFile(string path); + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + public extern bool ExistsFile(string path); + + /* The long time parameters in GetFileTime and + * SetFileTime correspond to Windows file times (ticks + * from DateTime(1/1/1601 00:00 GMT)) + */ + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + private extern bool GetFileTime(IntPtr handle, out long creat, out long lastaccess, out long lastwrite); + + [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)] + private extern bool SetFileTime(IntPtr handle, long creat, long lastaccess, long lastwrite); + + public DateTime GetCreationTimeFile(string path) + { + long creat, lastaccess, lastwrite; + bool ret; + FileStream s = new FileStream(path, FileMode.Open, FileAccess.Read); + + ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite); + s.Close(); + + return DateTime.FromFileTime(creat); + } + + public DateTime GetLastAccessTimeFile(string path) + { + long creat, lastaccess, lastwrite; + bool ret; + FileStream s = new FileStream(path, FileMode.Open, FileAccess.Read); + + ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite); + s.Close(); + + return DateTime.FromFileTime(lastaccess); + } + + public DateTime GetLastWriteTimeFile(string path) + { + long creat, lastaccess, lastwrite; + bool ret; + FileStream s = new FileStream(path, FileMode.Open, FileAccess.Read); + + ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite); + s.Close(); + + return DateTime.FromFileTime(lastwrite); + } + + public void SetCreationTimeFile(string path, DateTime creationTime) + { + long creat, lastaccess, lastwrite; + bool ret; + FileStream s = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); + + // Get the existing times first + ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite); + + creat=creationTime.ToFileTime(); + + ret=SetFileTime(s.Handle, creat, lastaccess, lastwrite); + s.Close(); + } + + public void SetLastAccessTimeFile(string path, DateTime lastAccessTime) + { + long creat, lastaccess, lastwrite; + bool ret; + FileStream s = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); + + // Get the existing times first + ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite); + + lastaccess=lastAccessTime.ToFileTime(); + + ret=SetFileTime(s.Handle, creat, lastaccess, lastwrite); + s.Close(); + } + + public void SetLastWriteTimeFile(string path, DateTime lastWriteTime) + { + long creat, lastaccess, lastwrite; + bool ret; + FileStream s = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); + + // Get the existing times first + ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite); + + lastwrite=lastWriteTime.ToFileTime(); + + ret=SetFileTime(s.Handle, creat, lastaccess, lastwrite); + s.Close(); + } + + + public long FileLength(string path) + { + return 0; + } + + public long FileLength(IntPtr handle) + { + return 0; + } + + // Private implementation details + [DllImport("monowrapper", EntryPoint="mono_wrapper_environ", CharSet=CharSet.Ansi)] + private unsafe static extern IntPtr _getEnviron(); + + [DllImport("libc", EntryPoint="getpid")] + private unsafe static extern int _getPid(); [ DllImport("libm", EntryPoint="acos") ] public extern static double Acos(double d); @@ -600,5 +571,5 @@ namespace System.PAL [ DllImport("libm", EntryPoint="tanh") ] public extern static double Tanh(double d); - } -} + } +} diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index 15a6d4b7b76..0e46239e617 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,7 @@ +2001-12-11 Dick Porter + + * FileStream.cs: Use handles rather than casting file descriptors. + Added Handle property. Wed Nov 14 16:47:47 CET 2001 Paolo Molaro diff --git a/mcs/class/corlib/System.IO/FileAccess.cs b/mcs/class/corlib/System.IO/FileAccess.cs index 77bf1d9e380..c6eefb3aa6f 100644 --- a/mcs/class/corlib/System.IO/FileAccess.cs +++ b/mcs/class/corlib/System.IO/FileAccess.cs @@ -16,7 +16,7 @@ namespace System.IO { /// /// [Flags] - public enum FileAccess { + public enum FileAccess : int { /// /// diff --git a/mcs/class/corlib/System.IO/FileAttributes.cs b/mcs/class/corlib/System.IO/FileAttributes.cs index 56a4650d018..674bc249827 100644 --- a/mcs/class/corlib/System.IO/FileAttributes.cs +++ b/mcs/class/corlib/System.IO/FileAttributes.cs @@ -13,7 +13,7 @@ namespace System.IO { [Flags] - public enum FileAttributes + public enum FileAttributes : int { Archive, Compressed, @@ -31,4 +31,4 @@ namespace System.IO Temporary } -} \ No newline at end of file +} diff --git a/mcs/class/corlib/System.IO/FileMode.cs b/mcs/class/corlib/System.IO/FileMode.cs index c32a53408bf..2f6fbbee30f 100644 --- a/mcs/class/corlib/System.IO/FileMode.cs +++ b/mcs/class/corlib/System.IO/FileMode.cs @@ -15,7 +15,7 @@ namespace System.IO { /// /// - public enum FileMode { + public enum FileMode : int { /// /// diff --git a/mcs/class/corlib/System.IO/FileShare.cs b/mcs/class/corlib/System.IO/FileShare.cs index d9e25cad5b6..626b369e75a 100644 --- a/mcs/class/corlib/System.IO/FileShare.cs +++ b/mcs/class/corlib/System.IO/FileShare.cs @@ -16,7 +16,7 @@ namespace System.IO { /// /// [Flags] - public enum FileShare { + public enum FileShare : int { /// /// diff --git a/mcs/class/corlib/System.IO/FileStream.cs b/mcs/class/corlib/System.IO/FileStream.cs index 55c8be8fbc8..e587c4a5381 100644 --- a/mcs/class/corlib/System.IO/FileStream.cs +++ b/mcs/class/corlib/System.IO/FileStream.cs @@ -9,6 +9,7 @@ using System; using System.PAL; using System.Runtime.InteropServices; +using System.Threading; // fixme: I do not know how to handle errno when calling PInvoke functions // fixme: emit the correct exceptions everywhere @@ -19,23 +20,24 @@ namespace System.IO public class FileStream : Stream { private OpSys _os = Platform.OS; - private IntPtr fd; + private IntPtr fdhandle; private FileAccess acc; private bool owner; - public FileStream (IntPtr fd, FileAccess access) - : this (fd, access, true, 0, false) {} + public FileStream (IntPtr handle, FileAccess access) + : this (handle, access, true, 0, false) {} - public FileStream (IntPtr fd, FileAccess access, bool ownsHandle) - : this (fd, access, ownsHandle, 0, false) {} + public FileStream (IntPtr handle, FileAccess access, bool ownsHandle) + : this (handle, access, ownsHandle, 0, false) {} - public FileStream (IntPtr fd, FileAccess access, bool ownsHandle, int bufferSize) - : this (fd, access, ownsHandle, bufferSize, false) {} + public FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize) + : this (handle, access, ownsHandle, bufferSize, false) {} - public FileStream (IntPtr fd, FileAccess access, bool ownsHandle, + public FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync) { - fd = fd; + fdhandle = handle; + //acc = access; //owner = ownsHandle; } @@ -57,8 +59,14 @@ namespace System.IO public FileStream (string name, FileMode mode, FileAccess access, FileShare share, int buferSize, bool useAsync) { - if ((int)(fd = _os.OpenFile (name, mode, access, share)) == -1) + fdhandle = _os.OpenFile (name, mode, access, share); + + /* Implement error checking, with some sort of access + to the errno error reason + if(fdhandle == error) { throw new IOException(); + } + */ acc = access; owner = true; @@ -102,17 +110,17 @@ namespace System.IO unsafe public override long Length { get { - return _os.FileLength (fd); + return _os.FileLength (fdhandle); } } public override long Position { get { - return _os.SeekFile (fd, 0, SeekOrigin.Current); + return _os.SeekFile (fdhandle, 0, SeekOrigin.Current); } set { - _os.SeekFile (fd, value, SeekOrigin.Begin); + _os.SeekFile (fdhandle, value, SeekOrigin.Begin); } } @@ -123,7 +131,7 @@ namespace System.IO public override void Close () { if (owner) { - _os.CloseFile (fd); + _os.CloseFile (fdhandle); } } @@ -131,7 +139,7 @@ namespace System.IO int offset, int count) { - return _os.ReadFile (fd, buffer, offset, count); + return _os.ReadFile (fdhandle, buffer, offset, count); } public unsafe override int ReadByte () @@ -143,31 +151,26 @@ namespace System.IO throw new IOException(); if (res == 0) return -1; - + return val[0]; } public override long Seek (long offset, SeekOrigin origin) { - return _os.SeekFile (fd, offset, origin); + return _os.SeekFile (fdhandle, offset, origin); } public override void SetLength (long value) { - int res; - - if ((res = _os.SetLengthFile (fd, value)) == -1) - throw new IOException(); - - + _os.SetLengthFile (fdhandle, value); } public unsafe override void Write (byte[] buffer, int offset, int count) { - int res = _os.WriteFile (fd, buffer, offset, count); + int res = _os.WriteFile (fdhandle, buffer, offset, count); if (res != count) throw new IOException(); @@ -182,5 +185,11 @@ namespace System.IO Write (buf, 0, 1); } + public virtual IntPtr Handle + { + get { + return(fdhandle); + } + } } } diff --git a/mcs/class/corlib/System.IO/SeekOrigin.cs b/mcs/class/corlib/System.IO/SeekOrigin.cs index 12b7f7e91d7..8dcba507e01 100644 --- a/mcs/class/corlib/System.IO/SeekOrigin.cs +++ b/mcs/class/corlib/System.IO/SeekOrigin.cs @@ -15,7 +15,7 @@ namespace System.IO { /// /// - public enum SeekOrigin { + public enum SeekOrigin : int { /// /// diff --git a/mcs/class/corlib/System.IO/Stream.cs b/mcs/class/corlib/System.IO/Stream.cs index 3edc9173fcc..3edd77eb240 100755 --- a/mcs/class/corlib/System.IO/Stream.cs +++ b/mcs/class/corlib/System.IO/Stream.cs @@ -1,203 +1,210 @@ -// -// System.IO/Stream.cs -// -// Author: -// Dietmar Maurer (dietmar@ximian.com) -// -// (C) 2001 Ximian, Inc. http://www.ximian.com -// - -namespace System.IO -{ - - public abstract class Stream : MarshalByRefObject, IDisposable - { - // public static readonly Stream Null; - - static Stream () - { - //Null = new NullStream (); - } - - protected Stream () - { - } - - public abstract bool CanRead - { - get; - } - - public abstract bool CanSeek - { - get; - } - - public abstract bool CanWrite - { - get; - } - - public abstract long Length - { - get; - } - - public abstract long Position - { - get; - set; - } - - - public virtual void Close () - { - Flush (); - } - - public virtual void Dispose () - { - } - - protected virtual void Dispose (bool disposing) - { - } - - ~Stream () - { - } - - public abstract void Flush (); - - public abstract int Read (byte[] buffer, - int offset, - int count); - - public virtual int ReadByte () - { - byte[] buffer = new byte [1]; - - if (Read (buffer, 0, 1) == 1) - return buffer [0]; - - return -1; - } - - public abstract long Seek (long offset, - SeekOrigin origin); - - public abstract void SetLength (long value); - - public abstract void Write (byte[] buffer, - int offset, - int count); - - public virtual void WriteByte (byte value) - { - byte[] buffer = new byte [1]; - - buffer [0] = value; - - Write (buffer, 0, 1); - } - } - - class NullStream : Stream - { - private long position = 0; - private long length = System.Int64.MaxValue; - - public override bool CanRead - { - get { - return true; - } - } - - public override bool CanSeek - { - get { - return true; - } - } - - public override bool CanWrite - { - get { - return true; - } - } - - public override long Length - { - get { - return length; - } - } - - public override long Position - { - get { - return position; - } - set { - position = value; - } - } - - public override void Flush () - { - } - - public override int Read (byte[] buffer, - int offset, - int count) - { - int max = offset + count; - - for (int i = offset; i < max; i++) - buffer [i] = 0; - - return count; - } - - public override int ReadByte () - { - return 0; - } - - public override long Seek (long offset, - SeekOrigin origin) - { - switch (origin) { - case SeekOrigin.Begin: - position = offset; - break; - case SeekOrigin.Current: - position = position + offset; - break; - case SeekOrigin.End: - position = Length - offset; - break; - } - - return position; - } - - public override void SetLength (long value) - { - length = value; - } - - public override void Write (byte[] buffer, - int offset, - int count) - { - } - - public override void WriteByte (byte value) - { - } - - } -} +// +// System.IO/Stream.cs +// +// Author: +// Dietmar Maurer (dietmar@ximian.com) +// +// (C) 2001 Ximian, Inc. http://www.ximian.com +// + +using System.Threading; + +namespace System.IO +{ + + public abstract class Stream : MarshalByRefObject, IDisposable + { + // public static readonly Stream Null; + + static Stream () + { + //Null = new NullStream (); + } + + protected Stream () + { + } + + public abstract bool CanRead + { + get; + } + + public abstract bool CanSeek + { + get; + } + + public abstract bool CanWrite + { + get; + } + + public abstract long Length + { + get; + } + + public abstract long Position + { + get; + set; + } + + + public virtual void Close () + { + Flush (); + } + + public virtual void Dispose () + { + } + + protected virtual WaitHandle CreateWaitHandle() + { + return(null); + } + + protected virtual void Dispose (bool disposing) + { + } + + ~Stream () + { + } + + public abstract void Flush (); + + public abstract int Read (byte[] buffer, + int offset, + int count); + + public virtual int ReadByte () + { + byte[] buffer = new byte [1]; + + if (Read (buffer, 0, 1) == 1) + return buffer [0]; + + return -1; + } + + public abstract long Seek (long offset, + SeekOrigin origin); + + public abstract void SetLength (long value); + + public abstract void Write (byte[] buffer, + int offset, + int count); + + public virtual void WriteByte (byte value) + { + byte[] buffer = new byte [1]; + + buffer [0] = value; + + Write (buffer, 0, 1); + } + } + + class NullStream : Stream + { + private long position = 0; + private long length = System.Int64.MaxValue; + + public override bool CanRead + { + get { + return true; + } + } + + public override bool CanSeek + { + get { + return true; + } + } + + public override bool CanWrite + { + get { + return true; + } + } + + public override long Length + { + get { + return length; + } + } + + public override long Position + { + get { + return position; + } + set { + position = value; + } + } + + public override void Flush () + { + } + + public override int Read (byte[] buffer, + int offset, + int count) + { + int max = offset + count; + + for (int i = offset; i < max; i++) + buffer [i] = 0; + + return count; + } + + public override int ReadByte () + { + return 0; + } + + public override long Seek (long offset, + SeekOrigin origin) + { + switch (origin) { + case SeekOrigin.Begin: + position = offset; + break; + case SeekOrigin.Current: + position = position + offset; + break; + case SeekOrigin.End: + position = Length - offset; + break; + } + + return position; + } + + public override void SetLength (long value) + { + length = value; + } + + public override void Write (byte[] buffer, + int offset, + int count) + { + } + + public override void WriteByte (byte value) + { + } + + } +} diff --git a/mcs/class/corlib/System.Threading/ChangeLog b/mcs/class/corlib/System.Threading/ChangeLog index b549bd59516..4d8fc5fa113 100644 --- a/mcs/class/corlib/System.Threading/ChangeLog +++ b/mcs/class/corlib/System.Threading/ChangeLog @@ -1,3 +1,8 @@ +2001-12-11 Dick Porter + + * WaitHandle.cs: Implemented WaitAll(), WaitAny() and WaitOne() as + internal calls. + 2001-11-26 Dick Porter * Thread.cs: DataSlot uses a single system TLS slot, and a diff --git a/mcs/class/corlib/System.Threading/WaitHandle.cs b/mcs/class/corlib/System.Threading/WaitHandle.cs index 59b1df1c5e9..07728a7aef2 100755 --- a/mcs/class/corlib/System.Threading/WaitHandle.cs +++ b/mcs/class/corlib/System.Threading/WaitHandle.cs @@ -7,40 +7,42 @@ // (C) Ximian, Inc. http://www.ximian.com // +using System.Runtime.CompilerServices; namespace System.Threading { public abstract class WaitHandle : MarshalByRefObject, IDisposable { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern bool WaitAll_internal(WaitHandle[] handles, int ms, bool exitContext); + public static bool WaitAll(WaitHandle[] waitHandles) { - // FIXME - return(false); + return(WaitAll_internal(waitHandles, 0, false)); } public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { - // FIXME - return(false); + return(WaitAll_internal(waitHandles, millisecondsTimeout, false)); } public static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) { - // FIXME - return(false); + return(WaitAll_internal(waitHandles, timeout.Milliseconds, exitContext)); } + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern int WaitAny_internal(WaitHandle[] handles, int ms, bool exitContext); + public static int WaitAny(WaitHandle[] waitHandles) { - // FIXME - return(0); + return(WaitAny_internal(waitHandles, 0, false)); } public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { - // FIXME - return(0); + return(WaitAny_internal(waitHandles, millisecondsTimeout, exitContext)); } public static int WaitAny(WaitHandle[] waitHandles, @@ -49,22 +51,24 @@ namespace System.Threading timeout.Milliseconds > Int32.MaxValue) { throw new ArgumentOutOfRangeException("Timeout out of range"); } - // FIXME - return(0); + return(WaitAny_internal(waitHandles, timeout.Milliseconds, exitContext)); } public WaitHandle() { // FIXME } + public const int WaitTimeout = 258; + + private IntPtr handle = IntPtr.Zero; + public virtual IntPtr Handle { get { - // FIXME - return new IntPtr(); + return(handle); } set { - // FIXME + handle=value; } } @@ -72,6 +76,21 @@ namespace System.Threading Dispose(false); } + [MethodImplAttribute(MethodImplOptions.InternalCall)] + protected virtual extern bool WaitOne_internal(IntPtr handle, int ms, bool exitContext); + + public virtual bool WaitOne() { + return(WaitOne_internal(handle, 0, false)); + } + + public virtual bool WaitOne(int millisecondsTimeout, bool exitContext) { + return(WaitOne_internal(handle, millisecondsTimeout, exitContext)); + } + + public virtual bool WaitOne(TimeSpan timeout, bool exitContext) { + return(WaitOne_internal(handle, timeout.Milliseconds, exitContext)); + } + protected static readonly IntPtr InvalidHandle; private bool disposed = false; diff --git a/mcs/class/corlib/System/ChangeLog b/mcs/class/corlib/System/ChangeLog index 8979d3f2da5..f7d78fcbf23 100644 --- a/mcs/class/corlib/System/ChangeLog +++ b/mcs/class/corlib/System/ChangeLog @@ -1,3 +1,9 @@ +2001-12-11 Dick Porter + + * DateTime.cs: Implemented FromFileTime() and ToFileTime() + + * Console.cs: Use handles rather than casting file descriptors + 2001-12-08 Nick Drochak * Byte.cs (Parse): Start implementation. Parse(string) works, but diff --git a/mcs/class/corlib/System/Console.cs b/mcs/class/corlib/System/Console.cs index f8faa8d6ef7..8f1802331d5 100644 --- a/mcs/class/corlib/System/Console.cs +++ b/mcs/class/corlib/System/Console.cs @@ -8,6 +8,7 @@ // using System.IO; +using System.PAL; namespace System { @@ -17,6 +18,8 @@ namespace System { private static TextWriter stderr; private static TextReader stdin; + private static OpSys _os = Platform.OS; + static Console () { stderr = new StreamWriter (OpenStandardError ()); @@ -52,29 +55,32 @@ namespace System { public static Stream OpenStandardError (int bufferSize) { - return new FileStream ((IntPtr)2, FileAccess.Write, + return new FileStream (_os.StderrHandle, + FileAccess.Write, false, bufferSize); } public static Stream OpenStandardInput () { - return OpenStandardError (0); + return OpenStandardInput (0); } public static Stream OpenStandardInput (int bufferSize) { - return new FileStream ((IntPtr)0, FileAccess.Read, + return new FileStream (_os.StdinHandle, + FileAccess.Read, false, bufferSize); } public static Stream OpenStandardOutput () { - return OpenStandardError (0); + return OpenStandardOutput (0); } public static Stream OpenStandardOutput (int bufferSize) { - return new FileStream ((IntPtr)1, FileAccess.Write, + return new FileStream (_os.StdoutHandle, + FileAccess.Write, false, bufferSize); } diff --git a/mcs/class/corlib/System/DateTime.cs b/mcs/class/corlib/System/DateTime.cs index b3ba419d71a..dfeaeb51986 100644 --- a/mcs/class/corlib/System/DateTime.cs +++ b/mcs/class/corlib/System/DateTime.cs @@ -1,735 +1,741 @@ -// -// System.DateTime.cs -// -// author: -// Marcel Narings (marcel@narings.nl) -// -// (C) 2001 Marcel Narings - -using System; -using System.Globalization; -using System.Runtime.CompilerServices; - - -namespace System -{ - /// - /// The DateTime structure represents dates and time ranging from - /// 1-1-0001 12:00:00 AM to 31-12-9999 23:59:00 Common Era. - /// - /// - public struct DateTime : IComparable , IFormattable , IConvertible - { - long ticks; - - private const long MaxTicks = 3155378975999999999L; - private const long MinTicks = 0L; - private const int dp400 = 146097; - private const int dp100 = 36524; - private const int dp4 = 1461; - - public static readonly DateTime MaxValue = new DateTime (MaxTicks); - public static readonly DateTime MinValue = new DateTime (MinTicks); - - private enum Which - { - Day, - DayYear, - Month, - Year - }; - - private static int[] daysmonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - - private static long AbsoluteDays (int year, int month, int day) - { - int[] days; - int temp = 0, m=1 ; - - days = (IsLeapYear(year) ? daysmonthleap : daysmonth); - - while (m < month) - temp += days[m++]; - return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400)); - } - - private int FromTicks(Which what) - { - int num400, num100, num4, numyears; - int M =1; - - int[] days = daysmonth; - int totaldays = (int) (ticks / TimeSpan.TicksPerDay); - - num400 = (totaldays / dp400); - totaldays -= num400 * dp400; - - num100 = (totaldays / dp100); - if (num100 == 4) // leap - num100 = 3; - totaldays -= (num100 * dp100); - - num4 = totaldays / dp4; - totaldays -= (num4 * dp4); - - numyears = totaldays / 365 ; - - if (numyears == 4) //leap - numyears =3 ; - if (what == Which.Year ) - return num400*400 + num100*100 + num4*4 + numyears + 1; - - totaldays -= (numyears * 365) ; - if (what == Which.DayYear ) - return totaldays + 1; - - if ((numyears==3) && ((num100 == 3) || !(num4 == 24)) ) //31 dec leapyear - days = daysmonthleap; - - while (totaldays >= days[M]) - totaldays -= days[M++]; - - if (what == Which.Month ) - return M; - - return totaldays +1; - - - } - - - // Constructors - - /// - /// Constructs a DateTime for specified ticks - /// - /// - public DateTime (long newticks) - { - ticks = newticks; - - if ( newticks < MinValue.ticks || newticks > MaxValue.ticks) - throw new ArgumentOutOfRangeException (); - } - - public DateTime (int year, int month, int day) - : this (year, month, day,0,0,0,0) {} - - public DateTime (int year, int month, int day, int hour, int minute, int second) - : this (year, month, day, hour, minute, second, 0) {} - - public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond) - { - if ( year < 1 || year > 9999 || - month < 1 || month >12 || - day < 1 || day > DaysInMonth(year, month) || - hour < 0 || hour > 23 || - minute < 0 || minute > 59 || - second < 0 || second > 59 ) - throw new ArgumentOutOfRangeException() ; - - ticks = AbsoluteDays(year,month,day) * TimeSpan.TicksPerDay + - hour * TimeSpan.TicksPerHour + - minute * TimeSpan.TicksPerMinute + - second * TimeSpan.TicksPerSecond + - millisecond * TimeSpan.TicksPerMillisecond ; - - if (ticks < MinValue.ticks || ticks > MaxValue.ticks ) - throw new ArgumentException() ; - } - - public DateTime (int year, int month, int day, Calendar calendar) - : this (year, month, day, 0, 0, 0, 0, calendar) {} - - - public DateTime (int year, int month, int day, int hour, int minute, int second, Calendar calendar) - : this (year, month, day, hour, minute, second, 0, calendar) {} - - - public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar) - : this(year, month, day, hour, minute, second, millisecond) - { - if ( calendar == null) - throw new ArgumentNullException(); - } - - - /* Properties */ - - public DateTime Date - { - get - { - return new DateTime(ticks - (ticks % TimeSpan.TicksPerDay )) ; - } - } - - public int Day - { - get - { - return FromTicks(Which.Day); - } - } - - public DayOfWeek DayOfWeek - { - get - { - return ( (DayOfWeek) (((ticks / TimeSpan.TicksPerDay)+1) % 7) ); - } - } - - public int DayOfYear - { - get - { - return FromTicks(Which.DayYear); - } - } - - public int Hour - { - get - { - return ( (int) ((ticks % TimeSpan.TicksPerDay) / TimeSpan.TicksPerHour) ); - } - } - - public int Millisecond - { - get - { - return ( (int) (ticks % TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) ); - } - } - - public int Minute - { - get - { - return ( (int) (ticks % TimeSpan.TicksPerHour / TimeSpan.TicksPerMinute) ); - } - } - - public int Month - { - get - { - return FromTicks(Which.Month); - } - } - - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern long GetNow (); - - public static DateTime Now - { - get - { - return new DateTime (GetNow ()); - } - } - - public int Second - { - get - { - return (int) (ticks % TimeSpan.TicksPerMinute / TimeSpan.TicksPerSecond); - } - } - - public long Ticks - { - get - { - return ticks ; - } - } - - public TimeSpan TimeOfDay - { - get - { - return new TimeSpan(ticks % TimeSpan.TicksPerDay ); - } - - } - - //TODO implement - public static DateTime Today - { - get - { - return new DateTime (0); - } - } - - //TODO implement - public static DateTime UtcNow - { - get { - return new DateTime (0); - } - } - - public int Year - { - get - { - return FromTicks(Which.Year); - } - } - - /* methods */ - - public DateTime Add (TimeSpan ts) - { - long newticks ; - - newticks = ticks + ts.Ticks ; - - if (ts.Ticks < MinTicks || ts.Ticks > MaxTicks || - newticks < MinTicks || newticks > MaxTicks) - throw new ArgumentException (); - - return new DateTime (newticks); - } - - public DateTime AddDays (double days) - { - return AddMilliseconds (days * 86400000); - } - - public DateTime AddTicks (long t) - { - long newticks = ticks + t; - - if (tMaxTicks || newticksMaxTicks) - throw new ArgumentException (); - - return new DateTime(newticks); - } - - public DateTime AddHours (double hours) - { - return AddMilliseconds (hours * 3600000); - } - - public DateTime AddMilliseconds (double ms) - { - long msticks, newticks; - - msticks = (long) (ms += ms > 0 ? 0.5 : -0.5) * TimeSpan.TicksPerMillisecond ; - newticks = ticks + msticks ; - - if (msticks < MinTicks || msticks > MaxTicks || - newticks < MinTicks || newticks > MaxTicks) - throw new ArgumentException (); - - return new DateTime (newticks); - } - - public DateTime AddMinutes (double minutes) - { - return AddMilliseconds (minutes * 60000); - } - - public DateTime AddMonths (int months) - { - int day, month, year, maxday ; - DateTime temp ; - - day = this.Day; - month = this.Month + (months % 12); - year = this.Year + months/12 ; - - if (month < 1) - { - month = 12 + month ; - year -- ; - } - else if (month>12) - { - month = month -12; - year ++; - } - maxday = DaysInMonth(year, month); - if (day > maxday) - day = maxday; - - temp = new DateTime (year, month, day); - return temp.Add (this.TimeOfDay); - } - - public DateTime AddSeconds (double seconds) - { - return AddMilliseconds (seconds*1000); - } - - public DateTime AddYears (int years ) - { - return AddMonths(years * 12); - } - - public static int Compare (DateTime t1, DateTime t2) - { - if (t1.ticks < t2.ticks) - return -1; - else if (t1.ticks > t2.ticks) - return 1; - else - return 0; - } - - public int CompareTo (object v) - { - if ( v == null) - return 1; - - if (!(v is System.DateTime)) - throw new ArgumentException (Locale.GetText ( - "Value is not a System.DateTime")); - - return Compare (this, (DateTime) v); - } - - public static int DaysInMonth (int year, int month) - { - int[] days ; - - if (month < 1 || month >12) - throw new ArgumentOutOfRangeException (); - - days = (IsLeapYear(year) ? daysmonthleap : daysmonth); - return days[month]; - } - - public override bool Equals (object o) - { - if (!(o is System.DateTime)) - return false; - - return ((DateTime) o).ticks == ticks; - } - - public static bool Equals (DateTime t1, DateTime t2 ) - { - return (t1.ticks == t2.ticks ); - } - - // TODO: Implement me. - public static DateTime FromFileTime (long fileTime) - { - return new DateTime (0); - } - - // TODO: Implement me. - public static DateTime FromOADate (double d) - { - return new DateTime(0); - } - - // TODO: Implement me. - public string[] GetDateTimeFormats() - { - return null; - } - - //TODO: implement me - public string[] GetDateTimeFormats( char format ) - { - return null; - } - - // TODO: implement me - public string[] GetDateTimeFormats( IFormatProvider provider) - { - return null; - } - - //TODO: implement me - public string[] GetDateTimeFormats(char format,IFormatProvider provider ) - { - return null; - } - - public override int GetHashCode () - { - return (int) ticks; - } - - public TypeCode GetTypeCode () - { - return TypeCode.DateTime; - } - - public static bool IsLeapYear (int year) - { - return ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ; - } - - public static DateTime Parse (string s) - { - // TODO: Implement me - return new DateTime (0); - } - - public static DateTime Parse (string s, IFormatProvider fp) - { - // TODO: Implement me - return new DateTime (0); - } - - public static DateTime Parse (string s, NumberStyles style, IFormatProvider fp) - { - // TODO: Implement me - return new DateTime (0); - } - - public static DateTime ParseExact(string s, string format, IFormatProvider provider ) - { - // TODO: Implement me - return new DateTime (0); - } - - public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style ) - { - // TODO: Implement me - return new DateTime (0); - - } - - public static DateTime ParseExact( string s, string[] formats, IFormatProvider provider, DateTimeStyles style ) - { - // TODO: Implement me - return new DateTime (0); - - } - - public TimeSpan Subtract(DateTime dt ) - { - return new TimeSpan(ticks - dt.ticks ); - } - - public DateTime Subtract(TimeSpan ts) - { - return new DateTime(ticks - ts.Ticks ); - } - - public long ToFileTime() - { - // TODO: Implement me - return 0 ; - } - - public DateTime ToLocalTime() - { - // TODO Implement me - return new DateTime (0); - } - - public string ToLongDateString() - { - // TODO implement me - throw new NotImplementedException (); - } - - public string ToLongTimeString() - { - // TODO implement me - throw new NotImplementedException (); - } - - public double ToOADate() - { - // TODO implement me - return 0; - } - - public string ToShortDateString() - { - // TODO implement me - throw new NotImplementedException (); - } - - public string ToShortTimeString() - { - // TODO implement me - throw new NotImplementedException (); - } - - public override string ToString () - { - // TODO: Implement me - throw new NotImplementedException (); - } - - public string ToString (IFormatProvider fp) - { - // TODO: Implement me. - throw new NotImplementedException (); - } - - public string ToString (string format) - { - // TODO: Implement me. - throw new NotImplementedException (); - } - - public string ToString (string format, IFormatProvider fp) - { - // TODO: Implement me. - throw new NotImplementedException (); - } - - public DateTime ToUniversalTime() - { - // TODO: implement me - return new DateTime(0); - } - - /* OPERATORS */ - - public static DateTime operator +(DateTime d, TimeSpan t) - { - return new DateTime (d.ticks + t.Ticks); - } - - public static bool operator ==(DateTime d1, DateTime d2) - { - return (d1.ticks == d2.ticks); - } - - public static bool operator >(DateTime t1,DateTime t2) - { - return (t1.ticks > t2.ticks); - } - - public static bool operator >=(DateTime t1,DateTime t2) - { - return (t1.ticks >= t2.ticks); - } - - public static bool operator !=(DateTime d1, DateTime d2) - { - return (d1.ticks != d2.ticks); - } - - public static bool operator <(DateTime t1, DateTime t2) - { - return (t1.ticks < t2.ticks ); - } - - public static bool operator <=(DateTime t1,DateTime t2) - { - return (t1.ticks <= t2.ticks); - } - - public static TimeSpan operator -(DateTime d1,DateTime d2) - { - return new TimeSpan(d1.ticks - d2.ticks); - } - - public static DateTime operator -(DateTime d,TimeSpan t ) - { - return new DateTime (d.ticks - t.Ticks); - } - - public bool ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public byte ToByte(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public char ToChar(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - // TODO Implement me - public System.DateTime ToDateTime(IFormatProvider provider) - { - return new System.DateTime(this.ticks); - } - - public decimal ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public double ToDouble(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public Int16 ToInt16(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public Int32 ToInt32(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public Int64 ToInt64(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - [CLSCompliant(false)] - public SByte ToSByte(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public Single ToSingle(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - public object ToType(Type conversionType,IFormatProvider provider) - { - throw new InvalidCastException(); - } - - UInt16 System.IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - [CLSCompliant(false)] - public UInt32 ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - [CLSCompliant(false)] - public UInt64 ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException(); - } - } -} - -namespace System -{ - public enum DayOfWeek - { - Sunday, - Monday, - Tuesday, - Wednesday, - Thursday, - Friday, - Saturday - } -} - +// +// System.DateTime.cs +// +// author: +// Marcel Narings (marcel@narings.nl) +// +// (C) 2001 Marcel Narings + +using System; +using System.Globalization; +using System.Runtime.CompilerServices; + + +namespace System +{ + /// + /// The DateTime structure represents dates and time ranging from + /// 1-1-0001 12:00:00 AM to 31-12-9999 23:59:00 Common Era. + /// + /// + public struct DateTime : IComparable , IFormattable , IConvertible + { + long ticks; + + private const long MaxTicks = 3155378975999999999L; + private const long MinTicks = 0L; + private const int dp400 = 146097; + private const int dp100 = 36524; + private const int dp4 = 1461; + + // w32 file time starts counting from 1/1/1601 00:00 GMT + // which is the constant ticks from the .NET epoch + private const long w32file_epoch = 504911232000000000L; + + public static readonly DateTime MaxValue = new DateTime (MaxTicks); + public static readonly DateTime MinValue = new DateTime (MinTicks); + + private enum Which + { + Day, + DayYear, + Month, + Year + }; + + private static int[] daysmonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + private static long AbsoluteDays (int year, int month, int day) + { + int[] days; + int temp = 0, m=1 ; + + days = (IsLeapYear(year) ? daysmonthleap : daysmonth); + + while (m < month) + temp += days[m++]; + return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400)); + } + + private int FromTicks(Which what) + { + int num400, num100, num4, numyears; + int M =1; + + int[] days = daysmonth; + int totaldays = (int) (ticks / TimeSpan.TicksPerDay); + + num400 = (totaldays / dp400); + totaldays -= num400 * dp400; + + num100 = (totaldays / dp100); + if (num100 == 4) // leap + num100 = 3; + totaldays -= (num100 * dp100); + + num4 = totaldays / dp4; + totaldays -= (num4 * dp4); + + numyears = totaldays / 365 ; + + if (numyears == 4) //leap + numyears =3 ; + if (what == Which.Year ) + return num400*400 + num100*100 + num4*4 + numyears + 1; + + totaldays -= (numyears * 365) ; + if (what == Which.DayYear ) + return totaldays + 1; + + if ((numyears==3) && ((num100 == 3) || !(num4 == 24)) ) //31 dec leapyear + days = daysmonthleap; + + while (totaldays >= days[M]) + totaldays -= days[M++]; + + if (what == Which.Month ) + return M; + + return totaldays +1; + + + } + + + // Constructors + + /// + /// Constructs a DateTime for specified ticks + /// + /// + public DateTime (long newticks) + { + ticks = newticks; + + if ( newticks < MinValue.ticks || newticks > MaxValue.ticks) + throw new ArgumentOutOfRangeException (); + } + + public DateTime (int year, int month, int day) + : this (year, month, day,0,0,0,0) {} + + public DateTime (int year, int month, int day, int hour, int minute, int second) + : this (year, month, day, hour, minute, second, 0) {} + + public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond) + { + if ( year < 1 || year > 9999 || + month < 1 || month >12 || + day < 1 || day > DaysInMonth(year, month) || + hour < 0 || hour > 23 || + minute < 0 || minute > 59 || + second < 0 || second > 59 ) + throw new ArgumentOutOfRangeException() ; + + ticks = AbsoluteDays(year,month,day) * TimeSpan.TicksPerDay + + hour * TimeSpan.TicksPerHour + + minute * TimeSpan.TicksPerMinute + + second * TimeSpan.TicksPerSecond + + millisecond * TimeSpan.TicksPerMillisecond ; + + if (ticks < MinValue.ticks || ticks > MaxValue.ticks ) + throw new ArgumentException() ; + } + + public DateTime (int year, int month, int day, Calendar calendar) + : this (year, month, day, 0, 0, 0, 0, calendar) {} + + + public DateTime (int year, int month, int day, int hour, int minute, int second, Calendar calendar) + : this (year, month, day, hour, minute, second, 0, calendar) {} + + + public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar) + : this(year, month, day, hour, minute, second, millisecond) + { + if ( calendar == null) + throw new ArgumentNullException(); + } + + + /* Properties */ + + public DateTime Date + { + get + { + return new DateTime(ticks - (ticks % TimeSpan.TicksPerDay )) ; + } + } + + public int Day + { + get + { + return FromTicks(Which.Day); + } + } + + public DayOfWeek DayOfWeek + { + get + { + return ( (DayOfWeek) (((ticks / TimeSpan.TicksPerDay)+1) % 7) ); + } + } + + public int DayOfYear + { + get + { + return FromTicks(Which.DayYear); + } + } + + public int Hour + { + get + { + return ( (int) ((ticks % TimeSpan.TicksPerDay) / TimeSpan.TicksPerHour) ); + } + } + + public int Millisecond + { + get + { + return ( (int) (ticks % TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) ); + } + } + + public int Minute + { + get + { + return ( (int) (ticks % TimeSpan.TicksPerHour / TimeSpan.TicksPerMinute) ); + } + } + + public int Month + { + get + { + return FromTicks(Which.Month); + } + } + + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern long GetNow (); + + public static DateTime Now + { + get + { + return new DateTime (GetNow ()); + } + } + + public int Second + { + get + { + return (int) (ticks % TimeSpan.TicksPerMinute / TimeSpan.TicksPerSecond); + } + } + + public long Ticks + { + get + { + return ticks ; + } + } + + public TimeSpan TimeOfDay + { + get + { + return new TimeSpan(ticks % TimeSpan.TicksPerDay ); + } + + } + + //TODO implement + public static DateTime Today + { + get + { + return new DateTime (0); + } + } + + //TODO implement + public static DateTime UtcNow + { + get { + return new DateTime (0); + } + } + + public int Year + { + get + { + return FromTicks(Which.Year); + } + } + + /* methods */ + + public DateTime Add (TimeSpan ts) + { + long newticks ; + + newticks = ticks + ts.Ticks ; + + if (ts.Ticks < MinTicks || ts.Ticks > MaxTicks || + newticks < MinTicks || newticks > MaxTicks) + throw new ArgumentException (); + + return new DateTime (newticks); + } + + public DateTime AddDays (double days) + { + return AddMilliseconds (days * 86400000); + } + + public DateTime AddTicks (long t) + { + long newticks = ticks + t; + + if (tMaxTicks || newticksMaxTicks) + throw new ArgumentException (); + + return new DateTime(newticks); + } + + public DateTime AddHours (double hours) + { + return AddMilliseconds (hours * 3600000); + } + + public DateTime AddMilliseconds (double ms) + { + long msticks, newticks; + + msticks = (long) (ms += ms > 0 ? 0.5 : -0.5) * TimeSpan.TicksPerMillisecond ; + newticks = ticks + msticks ; + + if (msticks < MinTicks || msticks > MaxTicks || + newticks < MinTicks || newticks > MaxTicks) + throw new ArgumentException (); + + return new DateTime (newticks); + } + + public DateTime AddMinutes (double minutes) + { + return AddMilliseconds (minutes * 60000); + } + + public DateTime AddMonths (int months) + { + int day, month, year, maxday ; + DateTime temp ; + + day = this.Day; + month = this.Month + (months % 12); + year = this.Year + months/12 ; + + if (month < 1) + { + month = 12 + month ; + year -- ; + } + else if (month>12) + { + month = month -12; + year ++; + } + maxday = DaysInMonth(year, month); + if (day > maxday) + day = maxday; + + temp = new DateTime (year, month, day); + return temp.Add (this.TimeOfDay); + } + + public DateTime AddSeconds (double seconds) + { + return AddMilliseconds (seconds*1000); + } + + public DateTime AddYears (int years ) + { + return AddMonths(years * 12); + } + + public static int Compare (DateTime t1, DateTime t2) + { + if (t1.ticks < t2.ticks) + return -1; + else if (t1.ticks > t2.ticks) + return 1; + else + return 0; + } + + public int CompareTo (object v) + { + if ( v == null) + return 1; + + if (!(v is System.DateTime)) + throw new ArgumentException (Locale.GetText ( + "Value is not a System.DateTime")); + + return Compare (this, (DateTime) v); + } + + public static int DaysInMonth (int year, int month) + { + int[] days ; + + if (month < 1 || month >12) + throw new ArgumentOutOfRangeException (); + + days = (IsLeapYear(year) ? daysmonthleap : daysmonth); + return days[month]; + } + + public override bool Equals (object o) + { + if (!(o is System.DateTime)) + return false; + + return ((DateTime) o).ticks == ticks; + } + + public static bool Equals (DateTime t1, DateTime t2 ) + { + return (t1.ticks == t2.ticks ); + } + + public static DateTime FromFileTime (long fileTime) + { + return new DateTime (w32file_epoch + fileTime); + } + + // TODO: Implement me. + public static DateTime FromOADate (double d) + { + return new DateTime(0); + } + + // TODO: Implement me. + public string[] GetDateTimeFormats() + { + return null; + } + + //TODO: implement me + public string[] GetDateTimeFormats( char format ) + { + return null; + } + + // TODO: implement me + public string[] GetDateTimeFormats( IFormatProvider provider) + { + return null; + } + + //TODO: implement me + public string[] GetDateTimeFormats(char format,IFormatProvider provider ) + { + return null; + } + + public override int GetHashCode () + { + return (int) ticks; + } + + public TypeCode GetTypeCode () + { + return TypeCode.DateTime; + } + + public static bool IsLeapYear (int year) + { + return ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ; + } + + public static DateTime Parse (string s) + { + // TODO: Implement me + return new DateTime (0); + } + + public static DateTime Parse (string s, IFormatProvider fp) + { + // TODO: Implement me + return new DateTime (0); + } + + public static DateTime Parse (string s, NumberStyles style, IFormatProvider fp) + { + // TODO: Implement me + return new DateTime (0); + } + + public static DateTime ParseExact(string s, string format, IFormatProvider provider ) + { + // TODO: Implement me + return new DateTime (0); + } + + public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style ) + { + // TODO: Implement me + return new DateTime (0); + + } + + public static DateTime ParseExact( string s, string[] formats, IFormatProvider provider, DateTimeStyles style ) + { + // TODO: Implement me + return new DateTime (0); + + } + + public TimeSpan Subtract(DateTime dt ) + { + return new TimeSpan(ticks - dt.ticks ); + } + + public DateTime Subtract(TimeSpan ts) + { + return new DateTime(ticks - ts.Ticks ); + } + + public long ToFileTime() + { + if(ticks < w32file_epoch) { + throw new ArgumentOutOfRangeException("file time is not valid"); + } + + return(ticks - w32file_epoch); + } + + public DateTime ToLocalTime() + { + // TODO Implement me + return new DateTime (0); + } + + public string ToLongDateString() + { + // TODO implement me + throw new NotImplementedException (); + } + + public string ToLongTimeString() + { + // TODO implement me + throw new NotImplementedException (); + } + + public double ToOADate() + { + // TODO implement me + return 0; + } + + public string ToShortDateString() + { + // TODO implement me + throw new NotImplementedException (); + } + + public string ToShortTimeString() + { + // TODO implement me + throw new NotImplementedException (); + } + + public override string ToString () + { + // TODO: Implement me + throw new NotImplementedException (); + } + + public string ToString (IFormatProvider fp) + { + // TODO: Implement me. + throw new NotImplementedException (); + } + + public string ToString (string format) + { + // TODO: Implement me. + throw new NotImplementedException (); + } + + public string ToString (string format, IFormatProvider fp) + { + // TODO: Implement me. + throw new NotImplementedException (); + } + + public DateTime ToUniversalTime() + { + // TODO: implement me + return new DateTime(0); + } + + /* OPERATORS */ + + public static DateTime operator +(DateTime d, TimeSpan t) + { + return new DateTime (d.ticks + t.Ticks); + } + + public static bool operator ==(DateTime d1, DateTime d2) + { + return (d1.ticks == d2.ticks); + } + + public static bool operator >(DateTime t1,DateTime t2) + { + return (t1.ticks > t2.ticks); + } + + public static bool operator >=(DateTime t1,DateTime t2) + { + return (t1.ticks >= t2.ticks); + } + + public static bool operator !=(DateTime d1, DateTime d2) + { + return (d1.ticks != d2.ticks); + } + + public static bool operator <(DateTime t1, DateTime t2) + { + return (t1.ticks < t2.ticks ); + } + + public static bool operator <=(DateTime t1,DateTime t2) + { + return (t1.ticks <= t2.ticks); + } + + public static TimeSpan operator -(DateTime d1,DateTime d2) + { + return new TimeSpan(d1.ticks - d2.ticks); + } + + public static DateTime operator -(DateTime d,TimeSpan t ) + { + return new DateTime (d.ticks - t.Ticks); + } + + public bool ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public byte ToByte(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public char ToChar(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + // TODO Implement me + public System.DateTime ToDateTime(IFormatProvider provider) + { + return new System.DateTime(this.ticks); + } + + public decimal ToDecimal(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public double ToDouble(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public Int16 ToInt16(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public Int32 ToInt32(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public Int64 ToInt64(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + [CLSCompliant(false)] + public SByte ToSByte(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public Single ToSingle(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + public object ToType(Type conversionType,IFormatProvider provider) + { + throw new InvalidCastException(); + } + + UInt16 System.IConvertible.ToUInt16(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + [CLSCompliant(false)] + public UInt32 ToUInt32(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + [CLSCompliant(false)] + public UInt64 ToUInt64(IFormatProvider provider) + { + throw new InvalidCastException(); + } + } +} + +namespace System +{ + public enum DayOfWeek + { + Sunday, + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday + } +} + -- 2.25.1