diff --git a/src/libraries/Common/src/Interop/FreeBSD/Interop.Errors.cs b/src/libraries/Common/src/Interop/FreeBSD/Interop.Errors.cs
deleted file mode 100644
index d824c105e31..00000000000
--- a/src/libraries/Common/src/Interop/FreeBSD/Interop.Errors.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-internal static partial class Interop
-{
- /// Common Unix errno error codes.
- internal static partial class Errors
- {
- // These values were defined in:
- // include/errno.h
-
- internal const int EDEADLK = 11;
-
- internal const int EAGAIN = 35;
- internal const int EWOULDBLOCK = EAGAIN;
- internal const int EINPROGRESS = 36;
- internal const int EALREADY = 37;
- internal const int ENOTSOCK = 38;
- internal const int EDESTADDRREQ = 39;
- internal const int EMSGSIZE = 40;
- internal const int EPROTOTYPE = 41;
- internal const int ENOPROTOOPT = 42;
- internal const int EPROTONOSUPPORT = 43;
- internal const int ESOCKTNOSUPPORT = 44;
- internal const int EOPNOTSUPP = 45;
- internal const int ENOTSUP = EOPNOTSUPP;
- internal const int EPFNOSUPPORT = 46;
- internal const int EAFNOSUPPORT = 47;
- internal const int EADDRINUSE = 48;
- internal const int EADDRNOTAVAIL = 49;
- internal const int ENETDOWN = 50;
- internal const int ENETUNREACH = 51;
- internal const int ENETRESET = 52;
- internal const int ECONNABORTED = 53;
- internal const int ECONNRESET = 54;
- internal const int ENOBUFS = 55;
- internal const int EISCONN = 56;
- internal const int ENOTCONN = 57;
- internal const int ESHUTDOWN = 58;
- internal const int ETOOMANYREFS = 59;
- internal const int ETIMEDOUT = 60;
- internal const int ECONNREFUSED = 61;
- internal const int ELOOP = 62;
- internal const int ENAMETOOLONG = 63;
- internal const int EHOSTDOWN = 64;
- internal const int EHOSTUNREACH = 65;
- internal const int ENOTEMPTY = 66;
- internal const int EPROCLIM = 67;
- internal const int EUSERS = 68;
- internal const int EDQUOT = 69;
- internal const int ESTALE = 70;
- internal const int EREMOTE = 71;
- internal const int EBADRPC = 72;
- internal const int ERPCMISMATCH = 73;
- internal const int EPROGUNAVAIL = 74;
- internal const int EPROGMISMATCH = 75;
- internal const int EPROCUNAVAIL = 76;
- internal const int ENOLCK = 77;
- internal const int ENOSYS = 78;
- internal const int EFTYPE = 79;
- internal const int EAUTH = 80;
- internal const int ENEEDAUTH = 81;
- internal const int EIDRM = 82;
- internal const int ENOMSG = 83;
- internal const int EOVERFLOW = 84;
- internal const int ECANCELED = 85;
- internal const int EILSEQ = 86;
- internal const int ENOATTR = 87;
- internal const int EDOOFUS = 88;
- internal const int EBADMSG = 89;
- internal const int EMULTIHOP = 90;
- internal const int ENOLINK = 91;
- internal const int EPROTO = 92;
- internal const int ENOTCAPABLE = 93;
- internal const int ECAPMODE = 94;
- internal const int ENOTRECOVERABLE = 95;
- internal const int EOWNERDEAD = 96;
- internal const int ELAST = 96;
- }
-}
diff --git a/src/libraries/Common/src/Interop/Linux/Interop.Errors.cs b/src/libraries/Common/src/Interop/Linux/Interop.Errors.cs
deleted file mode 100644
index d371810d8d5..00000000000
--- a/src/libraries/Common/src/Interop/Linux/Interop.Errors.cs
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-internal static partial class Interop
-{
- /// Common Unix errno error codes.
- internal static partial class Errors
- {
- // These values were defined in:
- // include/asm-generic/errno.h
-
- internal const int EWOULDBLOCK = 11;
- internal const int EAGAIN = 11;
-
- internal const int EDEADLK = 35;
- internal const int EDEADLOCK = EDEADLK;
- internal const int ENAMETOOLONG = 36;
- internal const int ENOLCK = 37;
- internal const int ENOSYS = 38;
- internal const int ENOTEMPTY = 39;
- internal const int ELOOP = 40;
- internal const int ENOMSG = 42;
- internal const int EIDRM = 43;
- internal const int ECHRNG = 44;
- internal const int EL2NSYNC = 45;
- internal const int EL3HLT = 46;
- internal const int EL3RST = 47;
- internal const int ELNRNG = 48;
- internal const int EUNATCH = 49;
- internal const int ENOCSI = 50;
- internal const int EL2HLT = 51;
- internal const int EBADE = 52;
- internal const int EBADR = 53;
- internal const int EXFULL = 54;
- internal const int ENOANO = 55;
- internal const int EBADRQC = 56;
- internal const int EBADSLT = 57;
- internal const int EBFONT = 59;
- internal const int ENOSTR = 60;
- internal const int ENODATA = 61;
- internal const int ETIME = 62;
- internal const int ENOSR = 63;
- internal const int ENONET = 64;
- internal const int ENOPKG = 65;
- internal const int EREMOTE = 66;
- internal const int ENOLINK = 67;
- internal const int EADV = 68;
- internal const int ESRMNT = 69;
- internal const int ECOMM = 70;
- internal const int EPROTO = 71;
- internal const int EMULTIHOP = 72;
- internal const int EDOTDOT = 73;
- internal const int EBADMSG = 74;
- internal const int EOVERFLOW = 75;
- internal const int ENOTUNIQ = 76;
- internal const int EBADFD = 77;
- internal const int EREMCHG = 78;
- internal const int ELIBACC = 79;
- internal const int ELIBBAD = 80;
- internal const int ELIBSCN = 81;
- internal const int ELIBMAX = 82;
- internal const int ELIBEXEC = 83;
- internal const int EILSEQ = 84;
- internal const int ERESTART = 85;
- internal const int ESTRPIPE = 86;
- internal const int EUSERS = 87;
- internal const int ENOTSOCK = 88;
- internal const int EDESTADDRREQ = 89;
- internal const int EMSGSIZE = 90;
- internal const int EPROTOTYPE = 91;
- internal const int ENOPROTOOPT = 92;
- internal const int EPROTONOSUPPORT = 93;
- internal const int ESOCKTNOSUPPORT = 94;
- internal const int EOPNOTSUPP = 95;
- internal const int EPFNOSUPPORT = 96;
- internal const int EAFNOSUPPORT = 97;
- internal const int EADDRINUSE = 98;
- internal const int EADDRNOTAVAIL = 99;
- internal const int ENETDOWN = 100;
- internal const int ENETUNREACH = 101;
- internal const int ENETRESET = 102;
- internal const int ECONNABORTED = 103;
- internal const int ECONNRESET = 104;
- internal const int ENOBUFS = 105;
- internal const int EISCONN = 106;
- internal const int ENOTCONN = 107;
- internal const int ESHUTDOWN = 108;
- internal const int ETOOMANYREFS = 109;
- internal const int ETIMEDOUT = 110;
- internal const int ECONNREFUSED = 111;
- internal const int EHOSTDOWN = 112;
- internal const int EHOSTUNREACH = 113;
- internal const int EALREADY = 114;
- internal const int EINPROGRESS = 115;
- internal const int ESTALE = 116;
- internal const int EUCLEAN = 117;
- internal const int ENOTNAM = 118;
- internal const int ENAVAIL = 119;
- internal const int EISNAM = 120;
- internal const int EREMOTEIO = 121;
- internal const int EDQUOT = 122;
- internal const int ENOMEDIUM = 123;
- internal const int EMEDIUMTYPE = 124;
- internal const int ECANCELED = 125;
- internal const int ENOKEY = 126;
- internal const int EKEYEXPIRED = 127;
- internal const int EKEYREVOKED = 128;
- internal const int EKEYREJECTED = 129;
- internal const int EOWNERDEAD = 130;
- internal const int ENOTRECOVERABLE = 131;
- internal const int ERFKILL = 132;
- }
-}
diff --git a/src/libraries/Common/src/Interop/Linux/libc/Interop.inotify.cs b/src/libraries/Common/src/Interop/Linux/libc/Interop.inotify.cs
index b7b7cb1d45f..db3c6aacd62 100644
--- a/src/libraries/Common/src/Interop/Linux/libc/Interop.inotify.cs
+++ b/src/libraries/Common/src/Interop/Linux/libc/Interop.inotify.cs
@@ -22,8 +22,8 @@ internal static partial class Interop
int result = Interop.libc.inotify_rm_watch_extern(fd, wd);
if (result < 0)
{
- int hr = global::System.Runtime.InteropServices.Marshal.GetLastWin32Error();
- if (hr == Interop.Errors.EINVAL)
+ Error hr = Interop.System.GetLastError();
+ if (hr == Interop.Error.EINVAL)
{
// This specific case means that there was a deleted event in the queue that was not processed
// so this call is expected to fail since the WatchDescriptor is no longer valid and was cleaned
diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs
index 4c5ed40672d..35d2481cd4f 100644
--- a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs
+++ b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs
@@ -441,7 +441,7 @@ internal static partial class Interop
}
// OS X uses UTF-8. The conversion may not strip off all trailing \0s so remove them here
- return System.Text.Encoding.UTF8.GetString(pBuffer, result);
+ return global::System.Text.Encoding.UTF8.GetString(pBuffer, result);
}
///
diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs b/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs
index d34cb0cf73b..f7979941fba 100644
--- a/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs
+++ b/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs
@@ -1,48 +1,166 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using System;
+using System.Runtime.InteropServices;
+
internal static partial class Interop
{
/// Common Unix errno error codes.
- internal static partial class Errors
+ internal enum Error
{
- // These values were defined in:
- // include/asm-generic/errno-base.h
- // /usr/include/sys/errno.h
+ // These values were defined in src/Native/System.Native/fxerrno.h
+ //
+ // They compare against values obtaied via Interop.System.GetLastError() not Marshal.GetLastWin32Error()
+ // which obtains the raw errno that varies between unixes. The strong typing as an enum is meant to
+ // prevent confusing the two. Casting to or from int is suspect. Use GetLastErrorInfo() if you need to
+ // correlate these to the underlying platform values or obtain the correspodning error message.
+ //
- internal const int EPERM = 1;
- internal const int ENOENT = 2;
- internal const int ESRCH = 3;
- internal const int EINTR = 4;
- internal const int EIO = 5;
- internal const int ENXIO = 6;
- internal const int E2BIG = 7;
- internal const int ENOEXEC = 8;
- internal const int EBADF = 9;
- internal const int ECHILD = 10;
+ E2BIG = 0x10001, // Argument list too long.
+ EACCES = 0x10002, // Permission denied.
+ EADDRINUSE = 0x10003, // Address in use.
+ EADDRNOTAVAIL = 0x10004, // Address not available.
+ EAFNOSUPPORT = 0x10005, // Address family not supported.
+ EAGAIN = 0x10006, // Resource unavailable, try again (same value as EWOULDBLOCK),
+ EALREADY = 0x10007, // Connection already in progress.
+ EBADF = 0x10008, // Bad file descriptor.
+ EBADMSG = 0x10009, // Bad message.
+ EBUSY = 0x1000A, // Device or resource busy.
+ ECANCELED = 0x1000B, // Operation canceled.
+ ECHILD = 0x1000C, // No child processes.
+ ECONNABORTED = 0x1000D, // Connection aborted.
+ ECONNREFUSED = 0x1000E, // Connection refused.
+ ECONNRESET = 0x1000F, // Connection reset.
+ EDEADLK = 0x10010, // Resource deadlock would occur.
+ EDESTADDRREQ = 0x10011, // Destination address required.
+ EDOM = 0x10012, // Mathematics argument out of domain of function.
+ EDQUOT = 0x10013, // Reserved.
+ EEXIST = 0x10014, // File exists.
+ EFAULT = 0x10015, // Bad address.
+ EFBIG = 0x10016, // File too large.
+ EHOSTUNREACH = 0x10017, // Host is unreachable.
+ EIDRM = 0x10018, // Identifier removed.
+ EILSEQ = 0x10019, // Illegal byte sequence.
+ EINPROGRESS = 0x1001A, // Operation in progress.
+ EINTR = 0x1001B, // Interrupted function.
+ EINVAL = 0x1001C, // Invalid argument.
+ EIO = 0x1001D, // I/O error.
+ EISCONN = 0x1001E, // Socket is connected.
+ EISDIR = 0x1001F, // Is a directory.
+ ELOOP = 0x10020, // Too many levels of symbolic links.
+ EMFILE = 0x10021, // File descriptor value too large.
+ EMLINK = 0x10022, // Too many links.
+ EMSGSIZE = 0x10023, // Message too large.
+ EMULTIHOP = 0x10024, // Reserved.
+ ENAMETOOLONG = 0x10025, // Filename too long.
+ ENETDOWN = 0x10026, // Network is down.
+ ENETRESET = 0x10027, // Connection aborted by network.
+ ENETUNREACH = 0x10028, // Network unreachable.
+ ENFILE = 0x10029, // Too many files open in system.
+ ENOBUFS = 0x1002A, // No buffer space available.
+ ENODATA = 0x1002B, // No message is available on the STREAM head read queue.
+ ENODEV = 0x1002C, // No such device.
+ ENOENT = 0x1002D, // No such file or directory.
+ ENOEXEC = 0x1002E, // Executable file format error.
+ ENOLCK = 0x1002F, // No locks available.
+ ENOLINK = 0x10030, // Reserved.
+ ENOMEM = 0x10031, // Not enough space.
+ ENOMSG = 0x10032, // No message of the desired type.
+ ENOPROTOOPT = 0x10033, // Protocol not available.
+ ENOSPC = 0x10034, // No space left on device.
+ ENOSR = 0x10035, // No STREAM resources.
+ ENOSTR = 0x10036, // Not a STREAM.
+ ENOSYS = 0x10037, // Function not supported.
+ ENOTCONN = 0x10038, // The socket is not connected.
+ ENOTDIR = 0x10039, // Not a directory or a symbolic link to a directory.
+ ENOTEMPTY = 0x1003A, // Directory not empty.
+ ENOTRECOVERABLE = 0x1003B, // State not recoverable.
+ ENOTSOCK = 0x1003C, // Not a socket.
+ ENOTSUP = 0x1003D, // Not supported (same value as EOPNOTSUP).
+ ENOTTY = 0x1003E, // Inappropriate I/O control operation.
+ ENXIO = 0x1003F, // No such device or address.
+ EOVERFLOW = 0x10040, // Value too large to be stored in data type.
+ EOWNERDEAD = 0x10041, // Previous owner died.
+ EPERM = 0x10042, // Operation not permitted.
+ EPIPE = 0x10043, // Broken pipe.
+ EPROTO = 0x10044, // Protocol error.
+ EPROTONOSUPPORT = 0x10045, // Protocol not supported.
+ EPROTOTYPE = 0x10046, // Protocol wrong type for socket.
+ ERANGE = 0x10047, // Result too large.
+ EROFS = 0x10048, // Read-only file system.
+ ESPIPE = 0x10049, // Invalid seek.
+ ESRCH = 0x1004A, // No such process.
+ ESTALE = 0x1004B, // Reserved.
+ ETIME = 0x1004C, // Stream ioctl() timeout.
+ ETIMEDOUT = 0x1004D, // Connection timed out.
+ ETXTBSY = 0x1004E, // Text file busy.
+ EXDEV = 0x1004F, // Cross-device link.
- internal const int ENOMEM = 12;
- internal const int EACCES = 13;
- internal const int EFAULT = 14;
- internal const int ENOTBLK = 15;
- internal const int EBUSY = 16;
- internal const int EEXIST = 17;
- internal const int EXDEV = 18;
- internal const int ENODEV = 19;
- internal const int ENOTDIR = 20;
- internal const int EISDIR = 21;
- internal const int EINVAL = 22;
- internal const int ENFILE = 23;
- internal const int EMFILE = 24;
- internal const int ENOTTY = 25;
- internal const int ETXTBSY = 26;
- internal const int EFBIG = 27;
- internal const int ENOSPC = 28;
- internal const int ESPIPE = 29;
- internal const int EROFS = 30;
- internal const int EMLINK = 31;
- internal const int EPIPE = 32;
- internal const int EDOM = 33;
- internal const int ERANGE = 34;
+ // POSIX permits these to have the same value and we make them always equal so
+ // that CoreFX cannot introduce a dependency on distinguishing between them that
+ // would not work on all platforms.
+ EOPNOTSUPP = ENOTSUP, // Operation not supported on socket
+ EWOULDBLOCK = EAGAIN, // Operation would block
+ }
+
+ // Represents a platform-agnostic Error and underlying platform-specific errno
+ internal struct ErrorInfo
+ {
+ internal readonly Error Error;
+ internal readonly int Errno;
+
+ internal ErrorInfo(Error error)
+ {
+ Error = error;
+ Errno = Interop.System.ConvertErrorPalToPlatform(error);
+ }
+
+ internal ErrorInfo(int errno)
+ {
+ Error = Interop.System.ConvertErrorPlatformToPal(errno);
+ Errno = errno;
+ }
+
+ internal ErrorInfo(Error error, int errno)
+ {
+ Error = error;
+ Errno = errno;
+ }
+
+ internal string GetErrorMessage()
+ {
+ return Interop.System.StrError(Errno);
+ }
+ }
+
+ internal partial class System
+ {
+ internal static Error GetLastError()
+ {
+ return ConvertErrorPlatformToPal(Marshal.GetLastWin32Error());
+ }
+
+ internal static ErrorInfo GetLastErrorInfo()
+ {
+ return new ErrorInfo(Marshal.GetLastWin32Error());
+ }
+
+ internal static unsafe string StrError(int platformErrno)
+ {
+ const int maxErrorMessageLength = 1024; // length long enough for most any Unix error
+ byte* buffer = stackalloc byte[maxErrorMessageLength];
+ IntPtr message = StrErrorR(platformErrno, buffer, maxErrorMessageLength);
+ return Marshal.PtrToStringAnsi(message);
+ }
+
+ [DllImport(Libraries.SystemNative)]
+ internal static extern Error ConvertErrorPlatformToPal(int platformErrno);
+
+ [DllImport(Libraries.SystemNative)]
+ internal static extern int ConvertErrorPalToPlatform(Error error);
+
+ [DllImport(Libraries.SystemNative)]
+ private static unsafe extern IntPtr StrErrorR(int platformErrno, byte* buffer, int bufferSize);
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs b/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs
index 4950ab48e49..2d98fde03be 100644
--- a/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs
+++ b/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs
@@ -22,18 +22,19 @@ internal static partial class Interop
/// true if the system call should be retried due to it being interrupted; otherwise, false.
/// An exception will be thrown if the system call failed for any reason other than interruption.
///
- internal static bool CheckIo(long result, string path = null, bool isDirectory = false, Func errorRewriter = null)
+ internal static bool CheckIo(long result, string path = null, bool isDirectory = false, Func errorRewriter = null)
{
if (result < 0)
{
- int errno = Marshal.GetLastWin32Error();
+ ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
if (errorRewriter != null)
{
- errno = errorRewriter(errno);
+ errorInfo = errorRewriter(errorInfo);
}
- if (errno != Interop.Errors.EINTR)
+
+ if (errorInfo.Error != Error.EINTR)
{
- throw Interop.GetExceptionForIoErrno(errno, path, isDirectory);
+ throw Interop.GetExceptionForIoErrno(errorInfo, path, isDirectory);
}
return true;
}
@@ -53,17 +54,17 @@ internal static partial class Interop
}
///
- /// Gets an Exception to represent the supplied errno error code.
+ /// Gets an Exception to represent the supplied error info.
///
- /// The error code
+ /// The error info
/// The path with which this error is associated. This may be null.
/// true if the is known to be a directory; otherwise, false.
///
- internal static Exception GetExceptionForIoErrno(int errno, string path = null, bool isDirectory = false)
+ internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string path = null, bool isDirectory = false)
{
- switch (errno)
+ switch (errorInfo.Error)
{
- case Errors.ENOENT:
+ case Error.ENOENT:
if (isDirectory)
{
return !string.IsNullOrEmpty(path) ?
@@ -77,41 +78,41 @@ internal static partial class Interop
new FileNotFoundException(SR.IO_FileNotFound);
}
- case Errors.EACCES:
- case Errors.EBADF:
- case Errors.EPERM:
+ case Error.EACCES:
+ case Error.EBADF:
+ case Error.EPERM:
return !string.IsNullOrEmpty(path) ?
new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path)) :
new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName);
- case Errors.ENAMETOOLONG:
+ case Error.ENAMETOOLONG:
return new PathTooLongException(SR.IO_PathTooLong);
- case Errors.EWOULDBLOCK:
+ case Error.EWOULDBLOCK:
return !string.IsNullOrEmpty(path) ?
- new IOException(SR.Format(SR.IO_SharingViolation_File, path), errno) :
- new IOException(SR.IO_SharingViolation_NoFileName, errno);
+ new IOException(SR.Format(SR.IO_SharingViolation_File, path), errorInfo.Errno) :
+ new IOException(SR.IO_SharingViolation_NoFileName, errorInfo.Errno);
- case Errors.ECANCELED:
+ case Error.ECANCELED:
return new OperationCanceledException();
- case Errors.EFBIG:
+ case Error.EFBIG:
return new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_FileLengthTooBig);
- case Errors.EEXIST:
+ case Error.EEXIST:
if (!string.IsNullOrEmpty(path))
{
- return new IOException(SR.Format(SR.IO_FileExists_Name, path), errno);
+ return new IOException(SR.Format(SR.IO_FileExists_Name, path), errorInfo.Errno);
}
goto default;
default:
- return GetIOException(errno);
+ return GetIOException(errorInfo);
}
}
- internal static Exception GetIOException(int errno)
+ internal static Exception GetIOException(Interop.ErrorInfo errorInfo)
{
- return new IOException(libc.strerror(errno), errno);
+ return new IOException(errorInfo.GetErrorMessage(), errorInfo.Errno);
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/libc/Interop.ResourceLimits.cs b/src/libraries/Common/src/Interop/Unix/libc/Interop.ResourceLimits.cs
index efe0192d770..7147a79ad76 100644
--- a/src/libraries/Common/src/Interop/Unix/libc/Interop.ResourceLimits.cs
+++ b/src/libraries/Common/src/Interop/Unix/libc/Interop.ResourceLimits.cs
@@ -66,7 +66,7 @@ internal static partial class Interop
int result = getrlimit(resource, ref info);
if (result < 0)
{
- throw new System.ComponentModel.Win32Exception(SR.ResourceLimitQueryFailure);
+ throw new global::System.ComponentModel.Win32Exception(SR.ResourceLimitQueryFailure);
}
return info;
diff --git a/src/libraries/Common/src/Interop/Unix/libc/Interop.getcwd.cs b/src/libraries/Common/src/Interop/Unix/libc/Interop.getcwd.cs
index 5489372a60d..8e427cf08ab 100644
--- a/src/libraries/Common/src/Interop/Unix/libc/Interop.getcwd.cs
+++ b/src/libraries/Common/src/Interop/Unix/libc/Interop.getcwd.cs
@@ -45,7 +45,7 @@ internal static partial class Interop
}
// If we couldn't get the cwd with a MaxPath-sized buffer, something's wrong.
- throw Interop.GetExceptionForIoErrno(Interop.Errors.ENAMETOOLONG);
+ throw Interop.GetExceptionForIoErrno(new ErrorInfo(Interop.Error.ENAMETOOLONG));
}
private static unsafe string getcwd(byte* ptr, int bufferSize)
@@ -61,12 +61,12 @@ internal static partial class Interop
// Otherwise, if it failed due to the buffer being too small, return null;
// for anything else, throw.
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.ERANGE)
+ ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.ERANGE)
{
return null;
}
- throw Interop.GetExceptionForIoErrno(errno);
+ throw Interop.GetExceptionForIoErrno(errorInfo);
}
[DllImport(Libraries.Libc, SetLastError = true)]
diff --git a/src/libraries/Common/src/Interop/Unix/libc/Interop.getsetpriority.cs b/src/libraries/Common/src/Interop/Unix/libc/Interop.getsetpriority.cs
index 59a4df7b808..31de7ee0f0d 100644
--- a/src/libraries/Common/src/Interop/Unix/libc/Interop.getsetpriority.cs
+++ b/src/libraries/Common/src/Interop/Unix/libc/Interop.getsetpriority.cs
@@ -48,7 +48,7 @@ internal static partial class Interop
[DllImport(Libraries.Libc, SetLastError = true)]
internal static extern int setpriority(PriorityWhich which, int who, int prio);
- internal static System.Diagnostics.ThreadPriorityLevel GetThreadPriorityFromNiceValue(int nice)
+ internal static global::System.Diagnostics.ThreadPriorityLevel GetThreadPriorityFromNiceValue(int nice)
{
Debug.Assert((nice >= -20) && (nice <= 20));
return
@@ -61,7 +61,7 @@ internal static partial class Interop
ThreadPriorityLevel.Idle;
}
- internal static int GetNiceValueFromThreadPriority(System.Diagnostics.ThreadPriorityLevel priority)
+ internal static int GetNiceValueFromThreadPriority(global::System.Diagnostics.ThreadPriorityLevel priority)
{
return (priority == ThreadPriorityLevel.TimeCritical ? -20 :
priority == ThreadPriorityLevel.Highest ? -15 :
diff --git a/src/libraries/Common/src/Interop/Unix/libc/Interop.mountpoints.cs b/src/libraries/Common/src/Interop/Unix/libc/Interop.mountpoints.cs
index 7ec01d0184f..806bf7f5567 100644
--- a/src/libraries/Common/src/Interop/Unix/libc/Interop.mountpoints.cs
+++ b/src/libraries/Common/src/Interop/Unix/libc/Interop.mountpoints.cs
@@ -36,13 +36,13 @@ internal static partial class Interop
/// The drive name to retrieve the statfs data for.
/// The data retrieved from the mount point.
/// Returns true if data was filled with the results; otherwise, false.
- internal static bool TryGetStatFsForDriveName(string name, out statfs data, out int errno)
+ internal static bool TryGetStatFsForDriveName(string name, out statfs data, out ErrorInfo errorInfo)
{
data = default(statfs);
- errno = 0;
+ errorInfo = default(ErrorInfo);
if (get_statfs(name, out data) < 0)
{
- errno = Marshal.GetLastWin32Error();
+ errorInfo = Interop.System.GetLastErrorInfo();
return false;
}
return true;
@@ -56,12 +56,12 @@ internal static partial class Interop
internal static statfs GetStatFsForDriveName(string name)
{
statfs data;
- int errno;
- if (!TryGetStatFsForDriveName(name, out data, out errno))
+ ErrorInfo errorInfo;
+ if (!TryGetStatFsForDriveName(name, out data, out errorInfo))
{
- throw errno == Errors.ENOENT ?
- new System.IO.DriveNotFoundException(SR.Format(SR.IO_DriveNotFound_Drive, name)) : // match Win32 exception
- GetExceptionForIoErrno(errno, isDirectory: true);
+ throw errorInfo.Error == Error.ENOENT ?
+ new global::System.IO.DriveNotFoundException(SR.Format(SR.IO_DriveNotFound_Drive, name)) : // match Win32 exception
+ GetExceptionForIoErrno(errorInfo, isDirectory: true);
}
return data;
}
diff --git a/src/libraries/Common/src/Interop/Unix/libc/Interop.strerror.cs b/src/libraries/Common/src/Interop/Unix/libc/Interop.strerror.cs
deleted file mode 100644
index 024705b5ae9..00000000000
--- a/src/libraries/Common/src/Interop/Unix/libc/Interop.strerror.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Runtime.InteropServices;
-
-using size_t = System.IntPtr;
-
-internal static partial class Interop
-{
- internal static partial class libc
- {
- internal static string strerror(int errno)
- {
- string result = IsGnu ? strerror_gnu(errno) : strerror_xsi(errno);
- // System.Diagnostics.Debug.WriteLine("strerror: " + result + "\n" + System.Environment.StackTrace); // uncomment to aid debugging
- return result;
- }
-
- // strerror is not thread-safe; instead, there is the strerror_r function, which is thread-safe.
- // However, there are two versions of strerror_r:
- // - GNU: char* strerror_r(int, char*, size_t);
- // - XSI: int strerror_r(int, char*, size_T);
- // The former may or may not use the supplied buffer, and returns the error message string.
- // The latter stores the error message string into the supplied buffer.
- // Due to the varied behaviors, we don't want to just choose one signature
- // and try to use a heuristic to deduce which version we're dealing with. Instead,
- // we detect whether we're compiled against GNU's libc by trying to invoke its
- // version-getting method, and invoke the right signature based on that.
-
- private const int MaxErrorMessageLength = 1024; // length long enough for most any Unix error messages
-
- private static unsafe string strerror_gnu(int errno)
- {
- byte* buffer = stackalloc byte[MaxErrorMessageLength];
- IntPtr result = strerror_r_gnu(errno, buffer, (IntPtr)MaxErrorMessageLength);
- return Marshal.PtrToStringAnsi(result);
- }
-
- private static unsafe string strerror_xsi(int errno)
- {
- byte* buffer = stackalloc byte[MaxErrorMessageLength];
- int ignored = strerror_r_xsi(errno, buffer, (size_t)MaxErrorMessageLength);
-
- // We ignore the return value of strerror_r. The only three valid return values are 0
- // for success, EINVAL for an unknown errno value, and ERANGE if there's not enough
- // buffer space provided. For EINVAL, it'll still fill the buffer with a reasonable error
- // string (e.g. "Unknown error: 0x123"), and for ERANGE, it'll fill the buffer with as much
- // of the error as can it, null-terminated. For now we don't grow the buffer, we could
- // in the future if desired.
-
- return Marshal.PtrToStringAnsi((IntPtr)buffer);
- }
-
- [DllImport(Libraries.Libc, EntryPoint = "strerror_r")]
- private static extern unsafe IntPtr strerror_r_gnu(int errnum, byte* buf, size_t buflen);
-
- [DllImport(Libraries.Libc, EntryPoint = "strerror_r")]
- private static extern unsafe int strerror_r_xsi(int errnum, byte* buf, size_t buflen);
- }
-}
diff --git a/src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs b/src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
index f49ae4bd40e..548bf94cb1e 100644
--- a/src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
+++ b/src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
@@ -44,7 +44,7 @@ namespace Microsoft.Win32.SafeHandles
// Open the file.
int fd;
while (Interop.CheckIo(fd = Interop.libc.open(path, flags, mode), path, isDirectory: enoentDueToDirectory,
- errorRewriter: errno => (errno == Interop.Errors.EISDIR) ? Interop.Errors.EACCES : errno)) ;
+ errorRewriter: e => (e.Error == Interop.Error.EISDIR) ? new Interop.ErrorInfo(Interop.Error.EACCES) : e)) ;
Debug.Assert(fd >= 0);
handle.SetHandle((IntPtr)fd);
Debug.Assert(!handle.IsInvalid);
@@ -55,12 +55,12 @@ namespace Microsoft.Win32.SafeHandles
if (Interop.libcoreclr.GetFileInformationFromFd(fd, out buf) != 0)
{
handle.Dispose();
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error(), path);
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo(), path);
}
if ((buf.mode & Interop.libcoreclr.FileTypes.S_IFMT) == Interop.libcoreclr.FileTypes.S_IFDIR)
{
handle.Dispose();
- throw Interop.GetExceptionForIoErrno(Interop.Errors.EACCES, path, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(new Interop.ErrorInfo(Interop.Error.EACCES), path, isDirectory: true);
}
}
return handle;
diff --git a/src/libraries/Microsoft.Win32.Primitives/src/Microsoft.Win32.Primitives.csproj b/src/libraries/Microsoft.Win32.Primitives/src/Microsoft.Win32.Primitives.csproj
index c93c6ccee1a..aaaa2fb245a 100644
--- a/src/libraries/Microsoft.Win32.Primitives/src/Microsoft.Win32.Primitives.csproj
+++ b/src/libraries/Microsoft.Win32.Primitives/src/Microsoft.Win32.Primitives.csproj
@@ -39,8 +39,8 @@
Common\Interop\Unix\Interop.gnu_get_libc_version.cs
-
- Common\Interop\Unix\Interop.strerror.cs
+
+ Common\Interop\Unix\Interop.Errors.cs
diff --git a/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.Unix.cs b/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.Unix.cs
index 35ad5174a4f..e23f0c05952 100644
--- a/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.Unix.cs
+++ b/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.Unix.cs
@@ -11,7 +11,7 @@ namespace System.ComponentModel
{
private static string GetErrorMessage(int error)
{
- return Interop.libc.strerror(error);
+ return Interop.System.StrError(error);
}
}
}
diff --git a/src/libraries/System.Console/src/System.Console.csproj b/src/libraries/System.Console/src/System.Console.csproj
index 23809bc745a..f7f8712fa62 100644
--- a/src/libraries/System.Console/src/System.Console.csproj
+++ b/src/libraries/System.Console/src/System.Console.csproj
@@ -132,9 +132,6 @@
Common\Interop\Unix\Interop.snprintf.cs
-
- Common\Interop\Unix\Interop.strerror.cs
-
Common\Interop\Unix\Interop.GetFileInformation.cs"
@@ -146,25 +143,16 @@
-
- Common\Interop\FreeBSD\Interop.Errors.cs
-
Common\Interop\FreeBSD\Interop.OpenFlags.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\Interop.OpenFlags.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.OpenFlags.cs
diff --git a/src/libraries/System.Console/src/System/ConsolePal.Unix.cs b/src/libraries/System.Console/src/System/ConsolePal.Unix.cs
index f9f3f855b24..25c15bc856c 100644
--- a/src/libraries/System.Console/src/System/ConsolePal.Unix.cs
+++ b/src/libraries/System.Console/src/System/ConsolePal.Unix.cs
@@ -552,7 +552,7 @@ namespace System
{
// Don't throw in this case, as we'll be polling multiple locations looking for the file.
// But we still want to retry if the open is interrupted by a signal.
- if (Marshal.GetLastWin32Error() != Interop.Errors.EINTR)
+ if (Interop.System.GetLastError() != Interop.Error.EINTR)
{
fd = -1;
return false;
@@ -1194,9 +1194,9 @@ namespace System
{
int error = Marshal.GetLastWin32Error(); // Win32 error code from coreclr PAL, not a Unix errno value
throw Interop.GetExceptionForIoErrno(
- error == Interop.libcoreclr.ERROR_INVALID_PARAMETER ? Interop.Errors.EINVAL :
- error == Interop.libcoreclr.ERROR_NOT_ENOUGH_MEMORY ? Interop.Errors.ENOMEM :
- Interop.Errors.EIO);
+ error == Interop.libcoreclr.ERROR_INVALID_PARAMETER ? new Interop.ErrorInfo(Interop.Error.EINVAL) :
+ error == Interop.libcoreclr.ERROR_NOT_ENOUGH_MEMORY ? new Interop.ErrorInfo(Interop.Error.ENOMEM) :
+ new Interop.ErrorInfo(Interop.Error.EIO));
}
_handlerRegistered = register;
}
diff --git a/src/libraries/System.Diagnostics.Debug/src/System.Diagnostics.Debug.csproj b/src/libraries/System.Diagnostics.Debug/src/System.Diagnostics.Debug.csproj
index 2129c94829b..39f1b8c0da8 100644
--- a/src/libraries/System.Diagnostics.Debug/src/System.Diagnostics.Debug.csproj
+++ b/src/libraries/System.Diagnostics.Debug/src/System.Diagnostics.Debug.csproj
@@ -67,9 +67,6 @@
Common\Interop\Unix\libc\Interop.open.cs
-
- Common\Interop\Unix\libc\Interop.strerror.cs
-
Common\Interop\Unix\libc\Interop.syslog.cs
@@ -85,27 +82,18 @@
-
- Common\Interop\FreeBSD\Interop.Errors.cs
-
Common\Interop\FreeBSD\Interop.OpenFlags.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\Interop.OpenFlags.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.OpenFlags.cs
diff --git a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
index f6863f2d1fe..4bf50efaaea 100644
--- a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
+++ b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
@@ -272,9 +272,6 @@
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\Interop.ProcFsStat.cs
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs
index 8cc94afbe54..73b8743ab22 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs
@@ -164,7 +164,7 @@ namespace System.Diagnostics
// If the buffer was too small, loop around again and try with a larger buffer.
// Otherwise, bail.
- if (resultLength == 0 || Marshal.GetLastWin32Error() != Interop.Errors.ENAMETOOLONG)
+ if (resultLength == 0 || Interop.System.GetLastError() != Interop.Error.ENAMETOOLONG)
{
break;
}
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs
index d217b55a1c2..ebc83451fb3 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs
@@ -352,7 +352,7 @@ namespace System.Diagnostics
}
// Could not find the file
- throw new Win32Exception(Interop.Errors.ENOENT);
+ throw new Win32Exception(new Interop.ErrorInfo(Interop.Error.ENOENT).Errno);
}
/// Convert a number of "jiffies", or ticks, to a TimeSpan.
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs
index ce795e61c31..f02029a3521 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs
@@ -315,13 +315,13 @@ namespace System.Diagnostics
// Something went wrong, e.g. it's not a child process,
// or waitpid was already called for this child, or
// that the call was interrupted by a signal.
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR)
+ Interop.Error errno = Interop.System.GetLastError();
+ if (errno == Interop.Error.EINTR)
{
// waitpid was interrupted. Try again.
continue;
}
- else if (errno == Interop.Errors.ECHILD)
+ else if (errno == Interop.Error.ECHILD)
{
// waitpid was used with a non-child process. We won't be
// able to get an exit code, but we'll at least be able
@@ -335,14 +335,14 @@ namespace System.Diagnostics
}
else // error from kill
{
- errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.ESRCH)
+ errno = Interop.System.GetLastError();
+ if (errno == Interop.Error.ESRCH)
{
// Couldn't find the process; assume it's exited
SetExited();
return;
}
- else if (errno == Interop.Errors.EPERM)
+ else if (errno == Interop.Error.EPERM)
{
// Don't have permissions to the process; assume it's alive
return;
diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
index b4e1fcdf733..fa881fcdb9f 100644
--- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
+++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
@@ -96,9 +96,6 @@
Common\Interop\Unix\Interop.gnu_get_libc_version.cs
-
- Common\Interop\Unix\Interop.strerror.cs
-
Common\System\IO\PathInternal.Unix.cs
@@ -117,9 +114,6 @@
Common\Interop\Unix\Interop.setmntent.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\System\IO\PathInternal.CaseSensitive.cs
@@ -134,9 +128,6 @@
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\System\IO\PathInternal.CaseInsensitive.cs
@@ -154,9 +145,6 @@
Common\Interop\FreeBSD\Interop.Libraries.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs
index 55df3b5aa32..ec379bb168f 100644
--- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs
+++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs
@@ -26,20 +26,20 @@ namespace System.IO
get
{
Interop.libc.statfs data;
- int errno;
- if (Interop.libc.TryGetStatFsForDriveName(Name, out data, out errno))
+ Interop.ErrorInfo errorInfo;
+ if (Interop.libc.TryGetStatFsForDriveName(Name, out data, out errorInfo))
{
return GetDriveType(Interop.libc.GetMountPointFsType(data));
}
// This is one of the few properties that doesn't throw on failure,
// instead returning a value from the enum.
- switch (errno)
+ switch (errorInfo.Error)
{
- case Interop.Errors.ELOOP:
- case Interop.Errors.ENAMETOOLONG:
- case Interop.Errors.ENOENT:
- case Interop.Errors.ENOTDIR:
+ case Interop.Error.ELOOP:
+ case Interop.Error.ENAMETOOLONG:
+ case Interop.Error.ENOENT:
+ case Interop.Error.ENOTDIR:
return DriveType.NoRootDirectory;
default:
return DriveType.Unknown;
diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
index 787038f6b02..bfa4c63c877 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
+++ b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
@@ -45,9 +45,6 @@
Common\Interop\Unix\libc\Interop.read.cs
-
- Common\Interop\Unix\libc\Interop.strerror.cs
-
Common\Interop\Unix\Interop.Errors.cs
@@ -63,9 +60,6 @@
Common\Interop\Linux\Interop.inotify.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Unix\Interop.poll.cs
@@ -84,9 +78,6 @@
Common\Interop\OSX\Interop.Libraries.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.RunLoop.cs
diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
index 15efc090a2b..142f8cbc09a 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
+++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
@@ -145,7 +145,7 @@ namespace System.IO
SafeCreateHandle path = Interop.CoreFoundation.CFStringCreateWithCString(_fullDirectory);
if (path.IsInvalid)
{
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error(), _fullDirectory, true);
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo(), _fullDirectory, true);
}
// Take the CFStringRef and put it into an array to pass to the EventStream
@@ -153,7 +153,7 @@ namespace System.IO
if (arrPaths.IsInvalid)
{
path.Dispose();
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error(), _fullDirectory, true);
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo(), _fullDirectory, true);
}
// Create the callback for the EventStream
@@ -173,7 +173,7 @@ namespace System.IO
{
arrPaths.Dispose();
path.Dispose();
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error(), _fullDirectory, true);
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo(), _fullDirectory, true);
}
// Create and start our watcher thread then wait for the thread to initialize and start
diff --git a/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj b/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj
index 5ee9e2d63de..e322841c7e3 100644
--- a/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj
+++ b/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj
@@ -322,9 +322,6 @@
Common\Interop\Unix\Interop.remove.cs
-
- Common\Interop\Unix\Interop.strerror.cs
-
Common\Interop\Unix\Interop.write.cs
@@ -350,9 +347,6 @@
Common\System\IO\PathInternal.CaseSensitive.cs
-
- Common\Interop\FreeBSD\Interop.Errors.cs
-
Common\Interop\FreeBSD\Interop.dirent.cs
@@ -375,9 +369,6 @@
Common\System\IO\PathInternal.CaseSensitive.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\Interop.readdir.cs
@@ -405,9 +396,6 @@
Common\Interop\OSX\Interop.PathConfNames.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.Libraries.cs
diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileStream.cs b/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileStream.cs
index 79d358cad01..35f4ea3e0a1 100644
--- a/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileStream.cs
+++ b/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileStream.cs
@@ -1037,14 +1037,14 @@ namespace System.IO
long result = sysCall(fd, arg1, arg2);
if (result < 0)
{
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR)
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR)
{
continue;
}
else if (throwOnError)
{
- throw Interop.GetExceptionForIoErrno(errno, _path, isDirectory: false);
+ throw Interop.GetExceptionForIoErrno(errorInfo, _path, isDirectory: false);
}
}
return result;
diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystem.cs b/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystem.cs
index d9d874acb3c..1782a27aabf 100644
--- a/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystem.cs
+++ b/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystem.cs
@@ -57,17 +57,17 @@ namespace System.IO
// as a Creation and Deletion instead of a Rename and thus differ from Windows.
while (Interop.libc.link(sourceFullPath, destFullPath) < 0)
{
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR) // interrupted; try again
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR) // interrupted; try again
{
continue;
}
- else if (errno == Interop.Errors.EXDEV) // link fails across devices / mount points
+ else if (errorInfo.Error == Interop.Error.EXDEV) // rename fails across devices / mount points
{
CopyFile(sourceFullPath, destFullPath, overwrite: false);
break;
}
- else if (errno == Interop.Errors.ENOENT && !Directory.Exists(Path.GetDirectoryName(destFullPath))) // The parent directory of destFile can't be found
+ else if (errorInfo.Error == Interop.Error.ENOENT && !Directory.Exists(Path.GetDirectoryName(destFullPath))) // The parent directory of destFile can't be found
{
// Windows distinguishes between whether the directory or the file isn't found,
// and throws a different exception in these cases. We attempt to approximate that
@@ -76,11 +76,11 @@ namespace System.IO
// worst case in such a race condition (which could occur if the file system is
// being manipulated concurrently with these checks) is that we throw a
// FileNotFoundException instead of DirectoryNotFoundexception.
- throw Interop.GetExceptionForIoErrno(errno, destFullPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(errorInfo, destFullPath, isDirectory: true);
}
else
{
- throw Interop.GetExceptionForIoErrno(errno);
+ throw Interop.GetExceptionForIoErrno(errorInfo);
}
}
DeleteFile(sourceFullPath);
@@ -90,20 +90,20 @@ namespace System.IO
{
while (Interop.libc.unlink(fullPath) < 0)
{
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR) // interrupted; try again
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR) // interrupted; try again
{
continue;
}
- else if (errno == Interop.Errors.ENOENT) // already doesn't exist; nop
+ else if (errorInfo.Error == Interop.Error.ENOENT) // already doesn't exist; nop
{
break;
}
else
{
- if (errno == Interop.Errors.EISDIR)
- errno = Interop.Errors.EACCES;
- throw Interop.GetExceptionForIoErrno(errno, fullPath);
+ if (errorInfo.Error == Interop.Error.EISDIR)
+ errorInfo = new Interop.ErrorInfo(Interop.Error.EACCES);
+ throw Interop.GetExceptionForIoErrno(errorInfo, fullPath);
}
}
}
@@ -165,14 +165,14 @@ namespace System.IO
string root = Directory.InternalGetDirectoryRoot(fullPath);
if (!DirectoryExists(root))
{
- throw Interop.GetExceptionForIoErrno(Interop.Errors.ENOENT, fullPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(new Interop.ErrorInfo(Interop.Error.ENOENT), fullPath, isDirectory: true);
}
return;
}
// Create all the directories
int result = 0;
- int firstError = 0;
+ Interop.ErrorInfo firstError = default(Interop.ErrorInfo);
string errorString = fullPath;
while (stackDir.Count > 0)
{
@@ -182,29 +182,29 @@ namespace System.IO
throw new PathTooLongException(SR.IO_PathTooLong);
}
- int errno = 0;
- while ((result = Interop.libc.mkdir(name, (int)Interop.libc.Permissions.S_IRWXU)) < 0 && (errno = Marshal.GetLastWin32Error()) == Interop.Errors.EINTR) ;
- if (result < 0 && firstError == 0)
+ Interop.ErrorInfo errorInfo = default(Interop.ErrorInfo);
+ while ((result = Interop.libc.mkdir(name, (int)Interop.libc.Permissions.S_IRWXU)) < 0 && (errorInfo = Interop.System.GetLastErrorInfo()).Error == Interop.Error.EINTR) ;
+ if (result < 0 && firstError.Error == 0)
{
// While we tried to avoid creating directories that don't
// exist above, there are a few cases that can fail, e.g.
// a race condition where another process or thread creates
// the directory first, or there's a file at the location.
- if (errno != Interop.Errors.EEXIST)
+ if (errorInfo.Error != Interop.Error.EEXIST)
{
- firstError = errno;
+ firstError = errorInfo;
}
- else if (FileExists(name) || (!DirectoryExists(name, out errno) && errno == Interop.Errors.EACCES))
+ else if (FileExists(name) || (!DirectoryExists(name, out errorInfo) && errorInfo.Error == Interop.Error.EACCES))
{
// If there's a file in this directory's place, or if we have ERROR_ACCESS_DENIED when checking if the directory already exists throw.
- firstError = errno;
+ firstError = errorInfo;
errorString = name;
}
}
}
// Only throw an exception if creating the exact directory we wanted failed to work correctly.
- if (result < 0 && firstError != 0)
+ if (result < 0 && firstError.Error != 0)
{
throw Interop.GetExceptionForIoErrno(firstError, errorString, isDirectory: true);
}
@@ -214,15 +214,15 @@ namespace System.IO
{
while (Interop.libc.rename(sourceFullPath, destFullPath) < 0)
{
- int errno = Marshal.GetLastWin32Error();
- switch (errno)
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ switch (errorInfo.Error)
{
- case Interop.Errors.EINTR: // interrupted; try again
+ case Interop.Error.EINTR: // interrupted; try again
continue;
- case Interop.Errors.EACCES: // match Win32 exception
- throw new IOException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, sourceFullPath), errno);
+ case Interop.Error.EACCES: // match Win32 exception
+ throw new IOException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, sourceFullPath), errorInfo.Errno);
default:
- throw Interop.GetExceptionForIoErrno(errno, sourceFullPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(errorInfo, sourceFullPath, isDirectory: true);
}
}
}
@@ -231,7 +231,7 @@ namespace System.IO
{
if (!DirectoryExists(fullPath))
{
- throw Interop.GetExceptionForIoErrno(Interop.Errors.ENOENT, fullPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(new Interop.ErrorInfo(Interop.Error.ENOENT), fullPath, isDirectory: true);
}
RemoveDirectoryInternal(fullPath, recursive, throwOnTopLevelDirectoryNotFound: true);
}
@@ -285,56 +285,56 @@ namespace System.IO
while (Interop.libc.rmdir(fullPath) < 0)
{
- int errno = Marshal.GetLastWin32Error();
- switch (errno)
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ switch (errorInfo.Error)
{
- case Interop.Errors.EINTR: // interrupted; try again
+ case Interop.Error.EINTR: // interrupted; try again
continue;
- case Interop.Errors.EACCES:
- case Interop.Errors.EPERM:
- case Interop.Errors.EROFS:
- case Interop.Errors.EISDIR:
+ case Interop.Error.EACCES:
+ case Interop.Error.EPERM:
+ case Interop.Error.EROFS:
+ case Interop.Error.EISDIR:
throw new IOException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, fullPath)); // match Win32 exception
- case Interop.Errors.ENOENT:
+ case Interop.Error.ENOENT:
if (!throwOnTopLevelDirectoryNotFound)
{
return;
}
goto default;
default:
- throw Interop.GetExceptionForIoErrno(errno, fullPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(errorInfo, fullPath, isDirectory: true);
}
}
}
public override bool DirectoryExists(string fullPath)
{
- int errno;
- return DirectoryExists(fullPath, out errno);
+ Interop.ErrorInfo errorInfo;
+ return DirectoryExists(fullPath, out errorInfo);
}
- private static bool DirectoryExists(string fullPath, out int errno)
+ private static bool DirectoryExists(string fullPath, out Interop.ErrorInfo errorInfo)
{
- return FileExists(fullPath, Interop.libcoreclr.FileTypes.S_IFDIR, out errno);
+ return FileExists(fullPath, Interop.libcoreclr.FileTypes.S_IFDIR, out errorInfo);
}
public override bool FileExists(string fullPath)
{
- int errno;
- return FileExists(fullPath, Interop.libcoreclr.FileTypes.S_IFREG, out errno);
+ Interop.ErrorInfo errorInfo;
+ return FileExists(fullPath, Interop.libcoreclr.FileTypes.S_IFREG, out errorInfo);
}
- private static bool FileExists(string fullPath, int fileType, out int errno)
+ private static bool FileExists(string fullPath, int fileType, out Interop.ErrorInfo errorInfo)
{
Interop.libcoreclr.fileinfo fileinfo;
while (true)
{
- errno = 0;
+ errorInfo = default(Interop.ErrorInfo);
int result = Interop.libcoreclr.GetFileInformationFromPath(fullPath, out fileinfo);
if (result < 0)
{
- errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR)
+ errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR)
{
continue;
}
@@ -483,7 +483,7 @@ namespace System.IO
case Interop.libc.DType.DT_UNKNOWN:
// It's a symlink or unknown: stat to it to see if we can resolve it to a directory.
// If we can't (e.g.symlink to a file, broken symlink, etc.), we'll just treat it as a file.
- int errnoIgnored;
+ Interop.ErrorInfo errnoIgnored;
isDir = DirectoryExists(Path.Combine(dirPath.FullPath, name), out errnoIgnored);
break;
default:
@@ -556,7 +556,7 @@ namespace System.IO
Interop.libc.SafeDirHandle handle = Interop.libc.opendir(fullPath);
if (handle.IsInvalid)
{
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error(), fullPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo(), fullPath, isDirectory: true);
}
return handle;
}
diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystemObject.cs b/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystemObject.cs
index 54b25cd0135..7898671698e 100644
--- a/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystemObject.cs
+++ b/src/libraries/System.IO.FileSystem/src/System/IO/UnixFileSystemObject.cs
@@ -20,13 +20,15 @@ namespace System.IO
/// The last cached stat information about the file.
private Interop.libcoreclr.fileinfo _fileinfo;
- ///
- /// Whether we've successfully cached a stat structure.
- /// -1 if we need to refresh _fileinfo, 0 if we've successfully cached one,
- /// or any other value that serves as an errno error code from the
- /// last time we tried and failed to refresh _fileinfo.
- ///
- private int _fileinfoInitialized = -1;
+ enum InitializationState : byte
+ {
+ RefreshNeeded, // we need to refresh _fileInfo
+ SuccessfullyCached, // we've successfully cached the stat structure
+ ErrorEncountered // we hit an error on last try, get errno from _InitializatonErrno
+ }
+
+ private InitializationState _fileinfoInitialization;
+ private Interop.ErrorInfo _fileinfoInitializationError;
public UnixFileSystemObject(string fullPath, bool asDirectory)
{
@@ -83,7 +85,7 @@ namespace System.IO
// just changing its permissions accordingly.
EnsureStatInitialized();
IsReadOnlyAssumesInitialized = (value & FileAttributes.ReadOnly) != 0;
- _fileinfoInitialized = -1;
+ _fileinfoInitialization = InitializationState.RefreshNeeded;
}
}
@@ -159,12 +161,12 @@ namespace System.IO
{
get
{
- if (_fileinfoInitialized == -1)
+ if (_fileinfoInitialization == InitializationState.RefreshNeeded)
{
Refresh();
}
return
- _fileinfoInitialized == 0 && // avoid throwing if Refresh failed; instead just return false
+ _fileinfoInitialization == InitializationState.SuccessfullyCached && // avoid throwing if Refresh failed; instead just return false
_isDirectory == IsDirectoryAssumesInitialized;
}
}
@@ -210,13 +212,13 @@ namespace System.IO
private void SetAccessWriteTimes(IntPtr? accessTime, IntPtr? writeTime)
{
- _fileinfoInitialized = -1; // force a refresh so that we have an up-to-date times for values not being overwritten
+ _fileinfoInitialization = InitializationState.RefreshNeeded; // force a refresh so that we have an up-to-date times for values not being overwritten
EnsureStatInitialized();
Interop.libc.utimbuf buf;
buf.actime = accessTime ?? new IntPtr(_fileinfo.atime);
buf.modtime = writeTime ?? new IntPtr(_fileinfo.mtime);
while (Interop.CheckIo(Interop.libc.utime(_fullPath, ref buf), _fullPath, _isDirectory)) ;
- _fileinfoInitialized = -1;
+ _fileinfoInitialization = InitializationState.RefreshNeeded;
}
public long Length
@@ -238,16 +240,17 @@ namespace System.IO
result = Interop.libcoreclr.GetFileInformationFromPath(_fullPath, out _fileinfo);
if (result >= 0)
{
- _fileinfoInitialized = 0;
+ _fileinfoInitialization = InitializationState.SuccessfullyCached;
}
else
{
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR)
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR)
{
continue;
}
- _fileinfoInitialized = errno;
+ _fileinfoInitialization = InitializationState.ErrorEncountered;
+ _fileinfoInitializationError = errorInfo;
}
break;
}
@@ -255,15 +258,15 @@ namespace System.IO
private void EnsureStatInitialized()
{
- if (_fileinfoInitialized == -1)
+ if (_fileinfoInitialization == InitializationState.RefreshNeeded)
{
Refresh();
}
- if (_fileinfoInitialized != 0)
+ if (_fileinfoInitialization != InitializationState.SuccessfullyCached)
{
- int errno = _fileinfoInitialized;
- _fileinfoInitialized = -1;
+ Interop.ErrorInfo errorInfo = _fileinfoInitializationError;
+ _fileinfoInitialization = InitializationState.RefreshNeeded;
// Windows distinguishes between whether the directory or the file isn't found,
// and throws a different exception in these cases. We attempt to approximate that
@@ -275,8 +278,8 @@ namespace System.IO
// directoryError is true only if a FileNotExists error was provided and the parent
// directory of the file represented by _fullPath is nonexistent
- bool directoryError = (errno == Interop.Errors.ENOENT && !Directory.Exists(Path.GetDirectoryName(PathHelpers.TrimEndingDirectorySeparator(_fullPath)))); // The destFile's path is invalid
- throw Interop.GetExceptionForIoErrno(errno, _fullPath, directoryError);
+ bool directoryError = (errorInfo.Error == Interop.Error.ENOENT && !Directory.Exists(Path.GetDirectoryName(PathHelpers.TrimEndingDirectorySeparator(_fullPath)))); // The destFile's path is invalid
+ throw Interop.GetExceptionForIoErrno(errorInfo, _fullPath, directoryError);
}
}
}
diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj
index 315a4545177..aee188704db 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj
+++ b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj
@@ -140,9 +140,6 @@
Common\Interop\Unix\Interop.Permissions.cs
-
- Common\Interop\Unix\Interop.strerror.cs
-
Common\Interop\Unix\Interop.sysconf.cs
@@ -158,9 +155,6 @@
Common\Interop\Unix\Interop.ftruncate.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\Interop.Libraries.cs
@@ -189,9 +183,6 @@
Common\Interop\Unix\Interop.unlink.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.Libraries.cs
diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs
index 2aea09f81c9..ff80c640fbd 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs
+++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs
@@ -121,7 +121,7 @@ namespace System.IO.MemoryMappedFiles
}
if ((long)addr < 0)
{
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error());
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo());
}
// Based on the HandleInheritability, try to prevent the memory-mapped region
@@ -164,7 +164,7 @@ namespace System.IO.MemoryMappedFiles
Interop.libc.MemoryMappedSyncFlags.MS_SYNC | Interop.libc.MemoryMappedSyncFlags.MS_INVALIDATE);
if (result < 0)
{
- throw Interop.GetExceptionForIoErrno(Marshal.GetLastWin32Error());
+ throw Interop.GetExceptionForIoErrno(Interop.System.GetLastErrorInfo());
}
}
finally
diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
index e4e328860fe..ad87f1422e4 100644
--- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
+++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
@@ -190,9 +190,6 @@
Common\Interop\Unix\Interop.read.cs
-
- Common\Interop\Unix\Interop.strerror.cs
-
Common\Interop\Unix\Interop.unlink.cs
@@ -207,9 +204,6 @@
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Unix\Interop.fcntl.cs
@@ -224,9 +218,6 @@
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.OpenFlags.cs
diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs
index 646c05ed976..044c3e241ad 100644
--- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs
+++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs
@@ -54,13 +54,13 @@ namespace System.IO.Pipes
break;
}
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR)
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR)
{
// interrupted; try again
continue;
}
- else if (errno == Interop.Errors.EEXIST)
+ else if (errorInfo.Error == Interop.Error.EEXIST)
{
// FIFO already exists; nothing more to do
break;
@@ -68,7 +68,7 @@ namespace System.IO.Pipes
else
{
// something else; fail
- throw Interop.GetExceptionForIoErrno(errno, _path);
+ throw Interop.GetExceptionForIoErrno(errorInfo, _path);
}
}
diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs
index 0b42d350a62..2408ed01f00 100644
--- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs
+++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs
@@ -48,20 +48,20 @@ namespace System.IO.Pipes
break;
}
- int errno = Marshal.GetLastWin32Error();
- if (errno == Interop.Errors.EINTR)
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ if (errorInfo.Error == Interop.Error.EINTR)
{
// I/O was interrupted, try again
continue;
}
- else if (errno == Interop.Errors.EEXIST)
+ else if (errorInfo.Error == Interop.Error.EEXIST)
{
// directory already exists
break;
}
else
{
- throw Interop.GetExceptionForIoErrno(errno, PipeDirectoryPath, isDirectory: true);
+ throw Interop.GetExceptionForIoErrno(errorInfo, PipeDirectoryPath, isDirectory: true);
}
}
@@ -315,15 +315,15 @@ namespace System.IO.Pipes
long result = sysCall(fd, arg1, arg2);
if (result < 0)
{
- int errno = Marshal.GetLastWin32Error();
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
- if (errno == Interop.Errors.EINTR)
+ if (errorInfo.Error == Interop.Error.EINTR)
continue;
- if (errno == Interop.Errors.EPIPE)
+ if (errorInfo.Error == Interop.Error.EPIPE)
State = PipeState.Broken;
- throw Interop.GetExceptionForIoErrno(errno);
+ throw Interop.GetExceptionForIoErrno(errorInfo);
}
return result;
}
diff --git a/src/libraries/System.Private.Uri/src/System.Private.Uri.CoreCLR.csproj b/src/libraries/System.Private.Uri/src/System.Private.Uri.CoreCLR.csproj
index 1b219a1df4c..ba2d4f74962 100644
--- a/src/libraries/System.Private.Uri/src/System.Private.Uri.CoreCLR.csproj
+++ b/src/libraries/System.Private.Uri/src/System.Private.Uri.CoreCLR.csproj
@@ -125,9 +125,6 @@
Common\Interop\Unix\libc\Interop.open.cs
-
- Common\Interop\Unix\libc\Interop.strerror.cs
-
Common\Interop\Unix\libc\Interop.syslog.cs
@@ -144,27 +141,18 @@
-
- Common\Interop\FreeBSD\Interop.Errors.cs
-
Common\Interop\FreeBSD\Interop.OpenFlags.cs
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\Interop.OpenFlags.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\Interop.OpenFlags.cs
diff --git a/src/libraries/System.Runtime.Extensions/src/System.Runtime.Extensions.CoreCLR.csproj b/src/libraries/System.Runtime.Extensions/src/System.Runtime.Extensions.CoreCLR.csproj
index 2914da3cb4b..a909b5e98f9 100644
--- a/src/libraries/System.Runtime.Extensions/src/System.Runtime.Extensions.CoreCLR.csproj
+++ b/src/libraries/System.Runtime.Extensions/src/System.Runtime.Extensions.CoreCLR.csproj
@@ -124,9 +124,6 @@
Common\Interop\Unix\libc\Interop.gnu_get_libc_version.cs
-
- Common\Interop\Unix\libc\Interop.strerror.cs
-
Common\Interop\Unix\libcoreclr\Interop.EnsureOpenSslInitialized.cs
@@ -148,27 +145,18 @@
-
- Common\Interop\Linux\Interop.Errors.cs
-
Common\Interop\Linux\libc\Interop.PathConfNames.cs
-
- Common\Interop\OSX\Interop.Errors.cs
-
Common\Interop\OSX\libc\Interop.PathConfNames.cs
-
- Common\Interop\FreeBSD\Interop.Errors.cs
-
Common\Interop\FreeBSD\libc\Interop.PathConfNames.cs
diff --git a/src/libraries/System.Security.SecureString/src/System.Security.SecureString.csproj b/src/libraries/System.Security.SecureString/src/System.Security.SecureString.csproj
index 2271e73c7d4..d9e542c1026 100644
--- a/src/libraries/System.Security.SecureString/src/System.Security.SecureString.csproj
+++ b/src/libraries/System.Security.SecureString/src/System.Security.SecureString.csproj
@@ -81,9 +81,6 @@
Common\Interop\Unix\Interop.munmap.cs
-
- Common\Interop\Unix\Interop.strerror.cs
-
Common\Interop\Unix\Interop.sysconf.cs
diff --git a/src/libraries/System.Security.SecureString/src/System/Security/SecureString.Unix.cs b/src/libraries/System.Security.SecureString/src/System/Security/SecureString.Unix.cs
index b57a19392fd..49911c9602e 100644
--- a/src/libraries/System.Security.SecureString/src/System/Security/SecureString.Unix.cs
+++ b/src/libraries/System.Security.SecureString/src/System/Security/SecureString.Unix.cs
@@ -394,10 +394,10 @@ namespace System.Security
private static Exception CreateExceptionFromErrno()
{
- int errno = Marshal.GetLastWin32Error();
- return (errno == Interop.Errors.ENOMEM || errno == Interop.Errors.EPERM) ?
+ Interop.ErrorInfo errorInfo = Interop.System.GetLastErrorInfo();
+ return (errorInfo.Error == Interop.Error.ENOMEM || errorInfo.Error == Interop.Error.EPERM) ?
(Exception)new OutOfMemoryException(SR.OutOfMemory_MemoryResourceLimits) :
- (Exception)new InvalidOperationException(Interop.libc.strerror(errno));
+ (Exception)new InvalidOperationException(errorInfo.GetErrorMessage());
}
private static int RoundUpToPageSize(int bytes)