(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Linux / Linux.cs
blob5a51ec93a6b9d80d8230a7a4a711fd3d1334fd42
2 //
3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /*---------------------------------------------------------------------
26 XX X XXX
27 XX XX
28 XXX XX XXX XXXXX XX
29 XX XXX XX XX XX
30 XX XX XX XX XXXXX XX
31 XX XX XX XX XX XX X XX
32 XXXX XX XX XXX XXXXXXX XXXX
34 XXXXX
36 Copyright (c) 2001 Intel Corporation. All Rights Reserved.
38 CREATED: August 22, 2001
39 OWNER: Scott D Smith, Joel Marcey
40 VERSION: 1.0
41 ---------------------------------------------------------------------*/
43 using System;
44 using System.Runtime.InteropServices;
45 using System.Text;
46 using System.IO;
47 using System.Collections;
48 using System.Reflection;
49 using System.Runtime.CompilerServices;
51 namespace System.PAL
53 /// <summary>
54 /// Class that implements IOperatingSystem, providing the requested functionality through calls into APIs available in Linux
55 /// </summary>
56 internal class OpSys
58 private Hashtable _environment = null;
60 //----------------------------------
61 // Class Constants
62 //----------------------------------
63 private const int EOF = -1; // TODO: Linux: Is this true?
66 // For StdInputStream and StdOutputStream
67 private IntPtr Stdin;
68 private IntPtr Stdout;
69 private IntPtr Stderr;
71 //----------------------------------
72 // Class Fields
73 //----------------------------------
75 //----------------------------------
76 // Class Constructor
77 //----------------------------------
78 public OpSys()
80 Stdin=GetStdHandle(0);
81 Stdout=GetStdHandle(1);
82 Stderr=GetStdHandle(2);
86 //-------------------------------------------------
87 // Environment Services
88 //-------------------------------------------------
90 public string NewLineSequence
92 get
94 return "\n";
98 public char DirectorySeparator
102 return '/';
106 public char AltDirectorySeparator
110 return '\\';
114 public char VolumeSeparator
118 return '/';
122 public char PathSeparator
126 return ':';
130 public char[] InvalidPathChars
134 return new char[] { '\0' };
138 public char[] DirVolSeparatorChars
142 return new char[] { this.DirectorySeparator, this.AltDirectorySeparator, this.VolumeSeparator};
145 public char ExtensionCharacter
149 return '.';
153 public string GetEnvironmentVariable(string eVar)
155 return EnvironmentVariables[eVar].ToString();
158 public IDictionary EnvironmentVariables
162 if (_environment == null) {
163 IntPtr pp = _getEnviron(); // pointer to an array of char*
164 _environment = new Hashtable();
166 if (pp != IntPtr.Zero) {
167 IntPtr p;
168 bool done = false;
169 char[] delimiter = { '=' };
171 while (!done)
173 p = Marshal.ReadIntPtr(pp);
174 if (p != IntPtr.Zero)
176 string str = Marshal.PtrToStringAuto(p);
177 string[] ar = str.Split(delimiter, 2);
178 switch(ar.Length)
180 case 1:
181 _environment.Add(ar[0], "");
182 break;
183 case 2:
184 _environment.Add(ar[0], ar[1]);
185 break;
186 default:
187 //System.Diagnostics/.Debug.Assert(false); // this shouldn't happen
188 break;
191 else
193 done = true;
198 return _environment;
202 public string CommandLine
206 string path = Path.Combine(Path.Combine("/proc", _getPid().ToString()), "cmdline");
207 StreamReader stream = File.OpenText(path);
208 string res = stream.ReadToEnd();
209 stream.Close();
210 return res;
214 public string MachineName
218 return GetEnvironmentVariable("HOSTNAME");
222 public OperatingSystem OSVersion
226 return null;
230 // System.Path services
232 public string ChangeExtension(string path, string extension)
234 //System.Diagnostics/.Debug.WriteLine("Linux:ChangeExtension(System.String, System.String): Stub Method");
235 return null;
238 public string GetExtension(string path)
240 //System.Diagnostics/.Debug.WriteLine("Linux:GetExtension(System.String): Stub Method");
241 return null;
244 public string GetFileName(string path)
246 //System.Diagnostics/.Debug.WriteLine("Linux:GetFileName(System.String): Stub Method");
247 return null;
250 public string GetFileNameWithoutExtension(string path)
252 //System.Diagnostics/.Debug.WriteLine("Linux:GetFileNameWithoutExtension(System.String): Stub Method");
253 return null;
256 public string GetFullPath(string path)
258 //System.Diagnostics/.Debug.WriteLine("Linux:GetFullPath(System.String): Stub Method");
259 return null;
262 public string GetPathRoot(string path)
264 //System.Diagnostics/.Debug.WriteLine("Linux:GetPathRoot(System.String): Stub Method");
265 return null;
269 public string GetTempFileName()
271 //System.Diagnostics/.Debug.WriteLine("Linux:GetTempFileName(): Stub Method");
272 return null;
275 public string GetTempPath()
277 //System.Diagnostics/.Debug.WriteLine("Linux:GetTempPath(): Stub Method");
278 return null;
281 public bool HasExtension(string path)
283 //System.Diagnostics/.Debug.WriteLine("Linux:HasExtension(System.String): Stub Method");
284 return false;
287 public bool IsPathRooted(string path)
289 //System.Diagnostics/.Debug.WriteLine("Linux:IsPathRooted(System.String): Stub Method");
290 return false;
295 // System.Directory services
297 public void DeleteDirectory(string path, bool recursive)
299 //System.Diagnostics/.Debug.WriteLine("Linux:DeleteDirectory(System.String, System.Boolean): Stub Method");
302 public bool ExistsDirectory(string path)
304 //System.Diagnostics/.Debug.WriteLine("Linux:ExistsDirectory(System.String): Stub Method");
305 return false;
308 public DateTime GetCreationTimeDirectory(string path)
310 //System.Diagnostics/.Debug.WriteLine("Linux:GetCreationTimeDirectory(System.String): Stub Method");
311 return new DateTime(0);
314 [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
315 public extern string GetCurrentDirectory();
317 public string[] GetDirectories(string path, string searchPattern)
319 //System.Diagnostics/.Debug.WriteLine("Linux:GetDirectories(System.String,System.String): Stub Method");
320 return null;
323 public string[] GetFiles(string path, string searchPattern)
325 //System.Diagnostics/.Debug.WriteLine("Linux:GetFiles(System.String, System.String): Stub Method");
326 return null;
329 public string[] GetFileSystemEntries(string path, string searchPattern)
331 //System.Diagnostics/.Debug.WriteLine("Linux:GetFileSystemEntries(System.String, System.String): Stub Method");
332 return null;
335 public DateTime GetLastAccessTimeDirectory(string path)
337 //System.Diagnostics/.Debug.WriteLine("Linux:GetLastAccessTimeDirectory(System.String): Stub Method");
338 return new DateTime(0);
341 public DateTime GetLastWriteTimeDirectory(string path)
343 //System.Diagnostics/.Debug.WriteLine("Linux:GetLastWriteTimeDirectory(System.String): Stub Method");
344 return new DateTime(0);
347 public void MoveDirectory(string sourceDirName, string destDirName)
349 //System.Diagnostics/.Debug.WriteLine("Linux:MoveDirectory(System.String, System.String): Stub Method");
352 public void SetCreationTimeDirectory(string path, DateTime creationTime)
354 //System.Diagnostics/.Debug.WriteLine("Linux:SetCreationTimeDirectory(System.String, System.DateTime): Stub Method");
357 public void SetCurrentDirectory(string path)
359 //System.Diagnostics/.Debug.WriteLine("Linux:SetCurrentDirectory(System.String): Stub Method");
362 public void SetLastAccessTimeDirectory(string path, DateTime lastAccessTime)
364 //System.Diagnostics/.Debug.WriteLine("Linux:SetLastAccessTimeDirectory(System.String, System.DateTime): Stub Method");
367 public void SetLastWriteTimeDirectory(string path, DateTime lastWriteTime)
369 //System.Diagnostics/.Debug.WriteLine("Linux:SetLastWriteTimeDirectory(System.String, System.DateTime): Stub Method");
372 //-----------------------------------
373 // I/O Services
374 //-----------------------------------
376 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
377 private extern IntPtr GetStdHandle(int fd);
379 public IntPtr StdinHandle {
380 get {
381 return(Stdin);
385 public IntPtr StdoutHandle {
386 get {
387 return(Stdout);
391 public IntPtr StderrHandle {
392 get {
393 return(Stderr);
397 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
398 public extern void DeleteFile(string path);
400 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
401 public extern bool ExistsFile(string path);
403 /* The long time parameters in GetFileTime and
404 * SetFileTime correspond to Windows file times (ticks
405 * from DateTime(1/1/1601 00:00 GMT))
407 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
408 private extern static bool GetFileTime(IntPtr handle, out long creat, out long lastaccess, out long lastwrite);
410 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
411 private extern static bool SetFileTime(IntPtr handle, long creat, long lastaccess, long lastwrite);
413 public DateTime GetCreationTimeFile(string path)
415 long creat, lastaccess, lastwrite;
416 bool ret;
417 FileStream s = new FileStream(path, FileMode.Open, FileAccess.Read);
419 ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite);
420 s.Close();
422 return DateTime.FromFileTime(creat);
425 public DateTime GetLastAccessTimeFile(string path)
427 long creat, lastaccess, lastwrite;
428 bool ret;
429 FileStream s = new FileStream(path, FileMode.Open, FileAccess.Read);
431 ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite);
432 s.Close();
434 return DateTime.FromFileTime(lastaccess);
437 public DateTime GetLastWriteTimeFile(string path)
439 long creat, lastaccess, lastwrite;
440 bool ret;
441 FileStream s = new FileStream(path, FileMode.Open, FileAccess.Read);
443 ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite);
444 s.Close();
446 return DateTime.FromFileTime(lastwrite);
449 public void SetCreationTimeFile(string path, DateTime creationTime)
451 long creat, lastaccess, lastwrite;
452 bool ret;
453 FileStream s = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
455 // Get the existing times first
456 ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite);
458 creat=creationTime.ToFileTime();
460 ret=SetFileTime(s.Handle, creat, lastaccess, lastwrite);
461 s.Close();
464 public void SetLastAccessTimeFile(string path, DateTime lastAccessTime)
466 long creat, lastaccess, lastwrite;
467 bool ret;
468 FileStream s = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
470 // Get the existing times first
471 ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite);
473 lastaccess=lastAccessTime.ToFileTime();
475 ret=SetFileTime(s.Handle, creat, lastaccess, lastwrite);
476 s.Close();
479 public void SetLastWriteTimeFile(string path, DateTime lastWriteTime)
481 long creat, lastaccess, lastwrite;
482 bool ret;
483 FileStream s = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
485 // Get the existing times first
486 ret=GetFileTime(s.Handle, out creat, out lastaccess, out lastwrite);
488 lastwrite=lastWriteTime.ToFileTime();
490 ret=SetFileTime(s.Handle, creat, lastaccess, lastwrite);
491 s.Close();
495 public long FileLength(string path)
497 return 0;
500 // Private implementation details
501 [DllImport("monowrapper", EntryPoint="mono_wrapper_environ", CharSet=CharSet.Ansi)]
502 private unsafe static extern IntPtr _getEnviron();
504 [DllImport("libc", EntryPoint="getpid")]
505 private unsafe static extern int _getPid();