shithub: femtolisp

Download patch

ref: 62389c8990cafb8e99ae29b2bccbcd100ce4c7f0
parent: 10d16c10bed72a177a99e0a9a3f3caca6c38ce94
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Jan 13 20:50:07 EST 2025

add *os-version* (optional)

--- a/flisp.c
+++ b/flisp.c
@@ -1388,6 +1388,9 @@
 	cvalues_init();
 
 	set(symbol("*os-name*", false), cvalue_static_cstring(__os_name__));
+#if defined(__os_version__)
+	set(symbol("*os-version*", false), cvalue_static_cstring(__os_version__));
+#endif
 	FL(memory_exception_value) = fl_list2(FL_MemoryError, cvalue_static_cstring("out of memory"));
 
 	const builtinspec_t *b;
--- a/macos/platform.h
+++ b/macos/platform.h
@@ -27,6 +27,8 @@
 #include <wchar.h>
 
 #define __os_name__ "macos"
+extern char os_version[10];
+#define __os_version__ os_version
 
 #define nil NULL
 #define USED(x) ((void)(x))
--- a/sys_macos.c
+++ b/sys_macos.c
@@ -1,3 +1,4 @@
+#include <OSUtils.h>
 #include "flisp.h"
 #include "timefuncs.h"
 
@@ -70,6 +71,8 @@
 	return -1;
 }
 
+char os_version[10];
+
 static const uint8_t boot[] = {
 #include "flisp.boot.h"
 };
@@ -77,5 +80,15 @@
 int
 main(int argc, char **argv)
 {
+	SysEnvRec r;
+	memset(&r, 0, sizeof(r));
+	SysEnvirons(2, &r);
+	snprintf(
+		os_version, sizeof(boot),
+		"%d.%d.%d",
+		r.systemVersion>>8,
+		(r.systemVersion>>4)&0xf,
+		(r.systemVersion>>0)&0xf
+	);
 	flmain(boot, sizeof(boot), argc, argv);
 }