public static SystemCallError rb_sys_fail(string mesg, System.Exception e, Frame caller) { SystemCallError error = null; if (e is System.IO.FileNotFoundException || e is System.IO.DirectoryNotFoundException || e is System.IO.DriveNotFoundException) { error = new SystemCallError(string.Format(CultureInfo.InvariantCulture, "No such file or directory - {0}", mesg), (Class)Ruby.Runtime.Init.rb_mErrno.instance_variable_get("ENOENT"), Errno.ENOENT); } else if (e is System.IO.IOException) { if (e.Message.Contains("ready")) error = new SystemCallError(string.Format(CultureInfo.InvariantCulture, "No such device or address - {0}", mesg), (Class)Ruby.Runtime.Init.rb_mErrno.instance_variable_get("ENXIO"), Errno.ENXIO); } else if (e is System.UnauthorizedAccessException) { error = new SystemCallError(string.Format(CultureInfo.InvariantCulture, "Permission denied - {0}", mesg), (Class)Ruby.Runtime.Init.rb_mErrno.instance_variable_get("EACCES"), Errno.EACCES); } if (error == null) { int HRESULT = System.Runtime.InteropServices.Marshal.GetHRForException(e); int errno = HResultToPosixErrorCode(HRESULT); error = new SystemCallError(mesg); error.errno = errno; } if (e == null || (error.errno) == 0) Exception.rb_bug(string.Format(CultureInfo.InvariantCulture, "rb_sys_fail({0}) - errno == 0", (mesg != null ? mesg : "")), caller); return error; }
public static SystemCallError rb_sys_fail(string mesg, Frame caller) { if (Errno.errno == 0) Exception.rb_bug(string.Format(CultureInfo.InvariantCulture, "rb_sys_fail({0}) - errno == 0", (mesg != null ? mesg : "")), caller); SystemCallError error; if (Errno.errno == Errno.EPERM) { error = new SystemCallError("Operation not permitted", (Class)Ruby.Runtime.Init.rb_mErrno.instance_variable_get("EPERM"), Errno.EPERM); } else if (Errno.errno == Errno.EPERM) { error = new SystemCallError(string.Format(CultureInfo.InvariantCulture, "No such file or directory - {0}", mesg), (Class)Ruby.Runtime.Init.rb_mErrno.instance_variable_get("ENOENT"), Errno.ENOENT); } else if (Errno.errno == Errno.EPERM) { error = new SystemCallError(string.Format(CultureInfo.InvariantCulture, "Permission denied - {0}", mesg), (Class)Ruby.Runtime.Init.rb_mErrno.instance_variable_get("EACCES"), Errno.EACCES); } else { error = new SystemCallError(mesg); error.errno = Errno.errno; } return error; }