Skip to content

Commit 7113ba3

Browse files
committed
Move more functions to posix.cs
1 parent ead66d5 commit 7113ba3

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

Src/IronPython.Modules/nt.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -774,23 +774,6 @@ public override string __repr__(CodeContext context) {
774774
}
775775
}
776776

777-
[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
778-
public static uname_result uname() {
779-
Mono.Unix.Native.Utsname info;
780-
Mono.Unix.Native.Syscall.uname(out info);
781-
return new uname_result(info.sysname, info.nodename, info.release, info.version, info.machine);
782-
}
783-
784-
[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
785-
public static BigInteger getuid() {
786-
return Mono.Unix.Native.Syscall.getuid();
787-
}
788-
789-
[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
790-
public static BigInteger geteuid() {
791-
return Mono.Unix.Native.Syscall.geteuid();
792-
}
793-
794777
#endif
795778

796779
#if FEATURE_FILESYSTEM
@@ -1286,12 +1269,15 @@ public sealed class stat_result : PythonTuple {
12861269

12871270
internal stat_result(int mode) : this(new object[10] { mode, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, null) { }
12881271

1272+
[SupportedOSPlatform("linux")]
1273+
[SupportedOSPlatform("macos")]
12891274
internal stat_result(Mono.Unix.Native.Stat stat)
12901275
: this(new object[16] {Mono.Unix.Native.NativeConvert.FromFilePermissions(stat.st_mode), ToInt(stat.st_ino), ToInt(stat.st_dev), ToInt(stat.st_nlink), ToInt(stat.st_uid), ToInt(stat.st_gid), ToInt(stat.st_size),
12911276
ToInt(stat.st_atime), ToInt(stat.st_mtime), ToInt(stat.st_ctime),
12921277
stat.st_atime + stat.st_atime_nsec / (double)nanosecondsPerSeconds, stat.st_mtime + stat.st_mtime_nsec / (double)nanosecondsPerSeconds, stat.st_ctime + stat.st_ctime_nsec / (double)nanosecondsPerSeconds,
12931278
ToInt(stat.st_atime * nanosecondsPerSeconds + stat.st_atime_nsec), ToInt(stat.st_mtime * nanosecondsPerSeconds + stat.st_mtime_nsec), ToInt(stat.st_ctime * nanosecondsPerSeconds + stat.st_ctime_nsec) }, null) { }
12941279

1280+
[SupportedOSPlatform("windows")]
12951281
internal stat_result(int mode, ulong fileidx, long size, long st_atime_ns, long st_mtime_ns, long st_ctime_ns)
12961282
: this(new object[16] { mode, ToInt(fileidx), 0, 0, 0, 0, ToInt(size),
12971283
ToInt(st_atime_ns / nanosecondsPerSeconds), ToInt(st_mtime_ns / nanosecondsPerSeconds), ToInt(st_ctime_ns / nanosecondsPerSeconds),

Src/IronPython.Modules/posix.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using System.IO;
9+
using System.Numerics;
910
using System.Runtime.InteropServices;
1011
using System.Runtime.Versioning;
1112
using System.Text;
@@ -178,6 +179,31 @@ internal static void ftruncateUnix(int fd, long length) {
178179
}
179180

180181

182+
[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
183+
[SupportedOSPlatform("linux")]
184+
[SupportedOSPlatform("macos")]
185+
public static uname_result uname() {
186+
if (Syscall.uname(out Utsname info) == 0) {
187+
return new uname_result(info.sysname, info.nodename, info.release, info.version, info.machine);
188+
}
189+
throw GetLastUnixError(); // rare
190+
}
191+
192+
[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
193+
[SupportedOSPlatform("linux")]
194+
[SupportedOSPlatform("macos")]
195+
public static BigInteger getuid() {
196+
return Syscall.getuid();
197+
}
198+
199+
[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
200+
[SupportedOSPlatform("linux")]
201+
[SupportedOSPlatform("macos")]
202+
public static BigInteger geteuid() {
203+
return Syscall.geteuid();
204+
}
205+
206+
181207
[SupportedOSPlatform("linux")]
182208
[SupportedOSPlatform("macos")]
183209
private static void utimeUnix(string path, long atime_ns, long utime_ns) {

0 commit comments

Comments
 (0)