diff --git a/src/core/IronPython.Modules/nt.cs b/src/core/IronPython.Modules/nt.cs index 7a235f014..c51cd2602 100644 --- a/src/core/IronPython.Modules/nt.cs +++ b/src/core/IronPython.Modules/nt.cs @@ -526,8 +526,12 @@ static void linkWindows(string src, string dst) { } public static bool isatty(CodeContext context, int fd) { - if (context.LanguageContext.FileManager.TryGetStreams(fd, out var streams)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + return isattyUnix(fd); + } + if (context.LanguageContext.FileManager.TryGetStreams(fd, out var streams)) { return streams.IsConsoleStream(); + } return false; } diff --git a/src/core/IronPython.Modules/posix.cs b/src/core/IronPython.Modules/posix.cs index 0af1aaa7f..0066798a1 100644 --- a/src/core/IronPython.Modules/posix.cs +++ b/src/core/IronPython.Modules/posix.cs @@ -206,14 +206,16 @@ public static BigInteger geteuid() { [SupportedOSPlatform("linux")] [SupportedOSPlatform("macos")] private static void utimeUnix(string path, long atime_ns, long utime_ns) { - var atime = new Timespec(); - atime.tv_sec = atime_ns / 1_000_000_000; - atime.tv_nsec = atime_ns % 1_000_000_000; - var utime = new Timespec(); - utime.tv_sec = utime_ns / 1_000_000_000; - utime.tv_nsec = utime_ns % 1_000_000_000; - - if (Syscall.utimensat(Syscall.AT_FDCWD, path, new[] { atime, utime }, 0) == 0) return; + var atime = new Timespec { + tv_sec = atime_ns / 1_000_000_000, + tv_nsec = atime_ns % 1_000_000_000 + }; + var utime = new Timespec { + tv_sec = utime_ns / 1_000_000_000, + tv_nsec = utime_ns % 1_000_000_000 + }; + + if (Syscall.utimensat(Syscall.AT_FDCWD, path, [atime, utime], 0) == 0) return; throw GetLastUnixError(path); } @@ -225,6 +227,13 @@ private static void killUnix(int pid, int sig) { throw GetLastUnixError(); } + + [SupportedOSPlatform("linux")] + [SupportedOSPlatform("macos")] + private static bool isattyUnix(int fd) { + return Syscall.isatty(fd); + } + #endif } }