shithub: mc

Download patch

ref: e7afb8cbbda5e7e375a9fec5f61460cec1052c1a
parent: cb693d6d5d0f10028a65f97ca8cbd2d7de814c2b
author: Ori Bernstein <[email protected]>
date: Wed Sep 11 17:39:05 EDT 2013

A hack to make uname() usable for OS probing.

    It doesn't *actually* work, but we hardcode "Darwin" as the OS
    name on OSX.

--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -521,6 +521,16 @@
 
 /* system information */
 const uname	= {buf;	
+	buf.system[0] = 'D' castto(byte)
+	buf.system[1] = 'a' castto(byte)
+	buf.system[2] = 'r' castto(byte)
+	buf.system[3] = 'w' castto(byte)
+	buf.system[4] = 'i' castto(byte)
+	buf.system[5] = 'n' castto(byte)
+	buf.system[6] = 0
+	-> 0
+	/*
+	FIXME: THIS IS BROKEN. Miscompiled? DEBUG IT.
 	var mib : int[2]
 	var ret
 	var sys
@@ -536,6 +546,7 @@
 	if sysctl(mib[:], &sys, [][:]) < 0
 		ret = -1
 	;;
+	std.put("%s\n", sys)
 
 	mib[0] = 1 /* CTL_KERN */
 	mib[1] = 10 /* KERN_HOSTNAME */
@@ -566,6 +577,7 @@
 	;;
 
 	-> ret
+	*/
 }
 
 const sysctl = {mib, old, new
--- a/libstd/test.myr
+++ b/libstd/test.myr
@@ -1,5 +1,15 @@
 use std
 
+const ntstr = {s
+	var n
+
+	n = 0
+	while s[n] != 0 && n < s.len
+		n++
+	;;
+	-> s[:n]
+}
+
 const main = {args : byte[:][:]
 	var x : byte#[1024]
 	var sz
@@ -7,8 +17,15 @@
         var ctx
         var o
 	var a
+	var buf
 
 	std.put("The time is %l seconds past the epoch\n", std.now()/1000);
+	std.uname(&buf)
+	std.put("And you are running on:\n")
+	std.put("\tsystem:\t\"%s\"\n", ntstr(buf.system[:]))
+	std.put("\tnode:\t\"%s\"\n", ntstr(buf.node[:]))
+	std.put("\trelease:\t\"%s\"\n", ntstr(buf.release[:]))
+	std.put("\tmachine:\t\"%s\"\n", ntstr(buf.machine[:]))
         ctx = std.optinit("asdf:g?h", args)
 	std.put("arglen = %i\n", ctx.args.len)
         while !std.optdone(ctx)