| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- //
- // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- /*---------------------------------------------------------------------
- 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;
- using System.Runtime.CompilerServices;
- namespace System.PAL
- {
- /// <summary>
- /// Class that implements IOperatingSystem, providing the requested functionality through calls into APIs available in Linux
- /// </summary>
- internal class OpSys
- {
- 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
- //-----------------------------------
- [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);
- }
- }
- [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 static bool GetFileTime(IntPtr handle, out long creat, out long lastaccess, out long lastwrite);
- [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
- private extern static 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;
- }
- // 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();
- }
- }
|