Skip to content

Commit 1586538

Browse files
authored
Improve isatty on POSIX (#1904)
1 parent b5fce64 commit 1586538

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/core/IronPython.Modules/nt.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,12 @@ static void linkWindows(string src, string dst) {
526526
}
527527

528528
public static bool isatty(CodeContext context, int fd) {
529-
if (context.LanguageContext.FileManager.TryGetStreams(fd, out var streams))
529+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
530+
return isattyUnix(fd);
531+
}
532+
if (context.LanguageContext.FileManager.TryGetStreams(fd, out var streams)) {
530533
return streams.IsConsoleStream();
534+
}
531535
return false;
532536
}
533537

src/core/IronPython.Modules/posix.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,16 @@ public static BigInteger geteuid() {
206206
[SupportedOSPlatform("linux")]
207207
[SupportedOSPlatform("macos")]
208208
private static void utimeUnix(string path, long atime_ns, long utime_ns) {
209-
var atime = new Timespec();
210-
atime.tv_sec = atime_ns / 1_000_000_000;
211-
atime.tv_nsec = atime_ns % 1_000_000_000;
212-
var utime = new Timespec();
213-
utime.tv_sec = utime_ns / 1_000_000_000;
214-
utime.tv_nsec = utime_ns % 1_000_000_000;
215-
216-
if (Syscall.utimensat(Syscall.AT_FDCWD, path, new[] { atime, utime }, 0) == 0) return;
209+
var atime = new Timespec {
210+
tv_sec = atime_ns / 1_000_000_000,
211+
tv_nsec = atime_ns % 1_000_000_000
212+
};
213+
var utime = new Timespec {
214+
tv_sec = utime_ns / 1_000_000_000,
215+
tv_nsec = utime_ns % 1_000_000_000
216+
};
217+
218+
if (Syscall.utimensat(Syscall.AT_FDCWD, path, [atime, utime], 0) == 0) return;
217219
throw GetLastUnixError(path);
218220
}
219221

@@ -225,6 +227,13 @@ private static void killUnix(int pid, int sig) {
225227
throw GetLastUnixError();
226228
}
227229

230+
231+
[SupportedOSPlatform("linux")]
232+
[SupportedOSPlatform("macos")]
233+
private static bool isattyUnix(int fd) {
234+
return Syscall.isatty(fd);
235+
}
236+
228237
#endif
229238
}
230239
}

0 commit comments

Comments
 (0)