[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetC/libc/dirent dirent-glue.cs, 1.1, 1.2
From: |
Richard Baumann <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetC/libc/dirent dirent-glue.cs, 1.1, 1.2 |
Date: |
Sat, 23 Aug 2003 01:59:44 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetC/libc/dirent
In directory subversions:/tmp/cvs-serv12314/libc/dirent
Modified Files:
dirent-glue.cs
Log Message:
Move OpenSystem.C.Directory from pnetlib's csupport to pnetC.
Index: dirent-glue.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetC/libc/dirent/dirent-glue.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** dirent-glue.cs 22 Aug 2003 08:15:43 -0000 1.1
--- dirent-glue.cs 23 Aug 2003 05:59:42 -0000 1.2
***************
*** 24,27 ****
--- 24,156 ----
using OpenSystem.C;
+ namespace OpenSystem.C
+ {
+
+ using System.IO;
+ using System.Security;
+
+ public class Directory
+ {
+ // Internal state.
+ private long pos;
+ private String[] entries;
+ private String name;
+ private int nameMax;
+
+ // Constructor.
+ public Directory(IntPtr cname, IntPtr err, int nameMax)
+ {
+ this.pos = 0;
+ this.nameMax = nameMax;
+ try
+ {
+ name = Marshal.PtrToStringAnsi(cname);
+ name = Path.GetFullPath(name);
+ String[] tmp =
name.Split(Path.DirectorySeparatorChar,
+
Path.AltDirectorySeparatorChar);
+ for(int i = 0; i < tmp.Length; ++i)
+ {
+ if(tmp[i].Length > nameMax)
+ {
+ Marshal.WriteInt32(err,
36); // ENAMETOOLONG
+ return;
+ }
+ }
+ }
+ catch(ArgumentException)
+ {
+ Marshal.WriteInt32(err, 2); // ENOENT
+ return;
+ }
+ catch(SecurityException)
+ {
+ Marshal.WriteInt32(err, 13); // EACCES
+ return;
+ }
+ catch(PathTooLongException)
+ {
+ Marshal.WriteInt32(err, 36); //
ENAMETOOLONG
+ return;
+ }
+ Rewind(err);
+ }
+
+ // Property.
+ public long Pos
+ {
+ get { return pos; }
+ set { pos = value; }
+ }
+
+ // Methods.
+ public IntPtr Read(IntPtr err, IntPtr len)
+ {
+ if(pos == entries.Length)
+ {
+ return IntPtr.Zero;
+ }
+ if(pos >= 0 && pos < entries.Length)
+ {
+ String s = entries[pos++];
+ int length = s.Length;
+ if(length > nameMax)
+ {
+ Marshal.WriteInt32(err, 75); //
EOVERFLOW
+ length = nameMax;
+ }
+ Marshal.WriteInt32(len, length);
+ return Marshal.StringToHGlobalAnsi(s);
+ }
+ Marshal.WriteInt32(err, 2); // ENOENT
+ return IntPtr.Zero;
+ }
+ public void Rewind(IntPtr err)
+ {
+ try
+ {
+ entries =
System.IO.Directory.GetFileSystemEntries(name);
+ }
+ catch(ArgumentException)
+ {
+ Marshal.WriteInt32(err, 2); // ENOENT
+ return;
+ }
+ catch(SecurityException)
+ {
+ Marshal.WriteInt32(err, 13); // EACCES
+ return;
+ }
+ catch(DirectoryNotFoundException)
+ {
+ Marshal.WriteInt32(err, 2); // ENOENT
+ return;
+ }
+ catch(PathTooLongException)
+ {
+ Marshal.WriteInt32(err, 36); //
ENAMETOOLONG
+ return;
+ }
+ catch(IOException)
+ {
+ Marshal.WriteInt32(err, 20); // ENOTDIR
+ return;
+ }
+
+ int nlen = name.Length;
+ if(name[nlen-1] != Path.DirectorySeparatorChar
&&
+ name[nlen-1] !=
Path.AltDirectorySeparatorChar)
+ {
+ ++nlen;
+ }
+ for(int i = 0; i < entries.Length; ++i)
+ {
+ entries[i] = entries[i].Substring(0,
nlen);
+ }
+ }
+
+ }; // class Directory
+
+ }; // namespace OpenSystem.C
+
__module
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetC/libc/dirent dirent-glue.cs, 1.1, 1.2,
Richard Baumann <address@hidden> <=