if (p == IntPtr.Zero)
return null;
+ if (encoding == null)
+ throw new ArgumentNullException ("encoding");
+
int len = GetStringByteLength (p, encoding);
// Due to variable-length encoding schemes, GetStringByteLength() may
{
if (count < 0)
throw new ArgumentOutOfRangeException ("count", "< 0");
+ if (encoding == null)
+ throw new ArgumentNullException ("encoding");
if (stringArray == IntPtr.Zero)
return new string[count];
public static IntPtr StringToHeap (string s, int index, int count, Encoding encoding)
{
+ if (s == null)
+ return IntPtr.Zero;
+
+ if (encoding == null)
+ throw new ArgumentNullException ("encoding");
+
int min_byte_count = encoding.GetMaxByteCount(1);
char[] copy = s.ToCharArray (index, count);
byte[] marshal = new byte [encoding.GetByteCount (copy) + min_byte_count];
IntPtr mem = AllocHeap (marshal.Length);
if (mem == IntPtr.Zero)
- throw new OutOfMemoryException ();
+ throw new UnixIOException (Native.Errno.ENOMEM);
bool copied = false;
try {
switch (errno) {
case Native.Errno.EBADF:
case Native.Errno.EINVAL: return new ArgumentException (message, p);
+
case Native.Errno.ERANGE: return new ArgumentOutOfRangeException (message);
case Native.Errno.ENOTDIR: return new DirectoryNotFoundException (message, p);
- case Native.Errno.EFAULT: return new NullReferenceException (message, p);
+ case Native.Errno.ENOENT: return new FileNotFoundException (message, p);
- case Native.Errno.EACCESS:
- case Native.Errno.EISDIR: return new UnauthorizedAccessException (message, p);
+ case Native.Errno.EOPNOTSUPP:
+ case Native.Errno.EPERM: return new InvalidOperationException (message, p);
- case Native.Errno.ENOENT: return new FileNotFoundException (message, p);
+ case Native.Errno.ENOEXEC: return new InvalidProgramException (message, p);
case Native.Errno.EIO:
case Native.Errno.ENOSPC:
case Native.Errno.EROFS:
case Native.Errno.ESPIPE: return new IOException (message, p);
- case Native.Errno.EOPNOTSUPP:
- case Native.Errno.EPERM: return new InvalidOperationException (message, p);
-
- case Native.Errno.ENOEXEC: return new InvalidProgramException (message, p);
- case Native.Errno.ENOMEM: return new OutOfMemoryException (message, p);
+ case Native.Errno.EFAULT: return new NullReferenceException (message, p);
case Native.Errno.EOVERFLOW: return new OverflowException (message, p);
case Native.Errno.ENAMETOOLONG: return new PathTooLongException (message, p);
+
+ case Native.Errno.EACCES:
+ case Native.Errno.EISDIR: return new UnauthorizedAccessException (message, p);
+
default: /* ignore */ break;
}
return p;