Skip to content

Commit

Permalink
Move more functions to posix.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Jan 13, 2025
1 parent ead66d5 commit 7113ba3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
20 changes: 3 additions & 17 deletions Src/IronPython.Modules/nt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,23 +774,6 @@ public override string __repr__(CodeContext context) {
}
}

[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
public static uname_result uname() {
Mono.Unix.Native.Utsname info;
Mono.Unix.Native.Syscall.uname(out info);
return new uname_result(info.sysname, info.nodename, info.release, info.version, info.machine);
}

[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
public static BigInteger getuid() {
return Mono.Unix.Native.Syscall.getuid();
}

[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
public static BigInteger geteuid() {
return Mono.Unix.Native.Syscall.geteuid();
}

#endif

#if FEATURE_FILESYSTEM
Expand Down Expand Up @@ -1286,12 +1269,15 @@ public sealed class stat_result : PythonTuple {

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

[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
internal stat_result(Mono.Unix.Native.Stat stat)
: 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),
ToInt(stat.st_atime), ToInt(stat.st_mtime), ToInt(stat.st_ctime),
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,
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) { }

[SupportedOSPlatform("windows")]
internal stat_result(int mode, ulong fileidx, long size, long st_atime_ns, long st_mtime_ns, long st_ctime_ns)
: this(new object[16] { mode, ToInt(fileidx), 0, 0, 0, 0, ToInt(size),
ToInt(st_atime_ns / nanosecondsPerSeconds), ToInt(st_mtime_ns / nanosecondsPerSeconds), ToInt(st_ctime_ns / nanosecondsPerSeconds),
Expand Down
26 changes: 26 additions & 0 deletions Src/IronPython.Modules/posix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System;
using System.IO;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
Expand Down Expand Up @@ -178,6 +179,31 @@ internal static void ftruncateUnix(int fd, long length) {
}


[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
public static uname_result uname() {
if (Syscall.uname(out Utsname info) == 0) {
return new uname_result(info.sysname, info.nodename, info.release, info.version, info.machine);
}
throw GetLastUnixError(); // rare
}

[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
public static BigInteger getuid() {
return Syscall.getuid();
}

[PythonHidden(PlatformsAttribute.PlatformFamily.Windows)]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
public static BigInteger geteuid() {
return Syscall.geteuid();
}


[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
private static void utimeUnix(string path, long atime_ns, long utime_ns) {
Expand Down

0 comments on commit 7113ba3

Please sign in to comment.