Add dodgy uname based host OS detection
[scheme.git] / platform.scm
diff --git a/platform.scm b/platform.scm
new file mode 100644 (file)
index 0000000..bddc67d
--- /dev/null
@@ -0,0 +1,22 @@
+(define (slurp ip)
+  (with-output-to-string
+    (lambda ()
+      (let f ()
+       (let ([c (read-char ip)])
+         (unless (eof-object? c)
+           (write-char c)
+           (f)))))))
+
+(define (trim s)
+  (if (<= (string-length s) 0)
+      s
+      (if (char-whitespace?
+          (string-ref s (- (string-length s) 1)))
+         (trim (substring s 0 (- (string-length s) 1)))
+         s)))
+
+(define host-os
+  (string->symbol
+   (string-downcase
+    (trim (slurp (car (process "uname")))))))
+