commit 7d3b483
ohmu
·
2026-10-08 20:18:50 +0300 MSK
parent ad1088b
added all options from OpenBSD's uname
+2,
-2
1@@ -1,5 +1,5 @@
2 # runame
3
4-random uname output for your os
5+random uname output for your os, trying to match OpenBSD's uname in syntax
6
7-GNU and Linux won't be added
8+GNU and Linux won't be added, kys
M
runame.c
+174,
-7
1@@ -1,10 +1,15 @@
2 /* runame - random uname for your os */
3
4+/*
5+ * TODO: match os name to latest release version
6+ */
7+
8 #include <stdio.h>
9 #include <stdlib.h>
10+#include <unistd.h>
11 #include <sys/time.h>
12
13-const char *unames[] = {
14+const char *osnames[] = {
15 "OpenBSD",
16 "FreeBSD",
17 "DragonFly",
18@@ -21,15 +26,177 @@ const char *unames[] = {
19 "Haiku"
20 };
21
22-int
23-main(int argc, char *argv[])
24+const char *arches[] = {
25+ "amd64",
26+ "arm64",
27+ "aarch64",
28+ "i386",
29+ "x86_64",
30+ "sparc",
31+ "sparc64",
32+ "powerpc",
33+ "powerpc64",
34+ "mips64",
35+ "alpha",
36+ "arm",
37+ "armv7",
38+ "riscv64",
39+ "hppa",
40+ "ia64",
41+ "unknown"
42+};
43+
44+const char *releases[] = {
45+ "7.9",
46+ "14.1-RELEASE-p3",
47+ "10.0",
48+ "6.4-RELEASE",
49+ "5.11",
50+ "5.10",
51+ "24.0.0",
52+ "3",
53+ "B.11.31",
54+ "6.5",
55+ "V5.1",
56+ "5",
57+ "7.1.0",
58+ "1",
59+ "3.4.0"
60+};
61+
62+const char *versions[] = {
63+ "GENERIC.MP#1",
64+ "GENERIC#0",
65+ "FreeBSD 14.1-RELEASE-p3 GENERIC",
66+ "NetBSD 10.0 (GENERIC)",
67+ "11.4.42.111.0",
68+ "illumos-a1b2c3d4e5",
69+ "Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000",
70+ "7",
71+ "U",
72+ "07202013",
73+ "2650",
74+ "7.1.4",
75+ "hrev57937"
76+};
77+
78+const char *names[] = {
79+ "openbsd.my.domain",
80+ "Amnesiac",
81+ "solaris",
82+ "openindiana",
83+ "omnios",
84+ "minix",
85+ "localhost",
86+ "Mac.local",
87+ "MacBook-Pro.local",
88+ "IRIS",
89+ "shredder"
90+};
91+
92+int
93+randomvalue(const char *arr[], int len)
94 {
95- int n, len;
96+ int n;
97 struct timeval tv;
98 gettimeofday(&tv, NULL);
99 srand(tv.tv_sec ^ tv.tv_usec);
100- len = sizeof(unames) / sizeof(unames[0]);
101 n = rand() % len;
102- printf("%s\n", unames[n]);
103- return 0;
104+
105+ return n;
106+}
107+
108+void
109+osname(void)
110+{
111+ int size;
112+
113+ size = sizeof(osnames) / sizeof(osnames[0]);
114+
115+ printf("%s ", osnames[randomvalue(osnames, size)]);
116+}
117+
118+void
119+arch(void)
120+{
121+ int size;
122+
123+ size = sizeof(arches) / sizeof(arches[0]);
124+
125+ printf("%s ", arches[randomvalue(arches, size)]);
126+}
127+
128+void
129+release(void)
130+{
131+ int size;
132+
133+ size = sizeof(releases) / sizeof(releases[0]);
134+
135+ printf("%s ", releases[randomvalue(releases, size)]);
136+}
137+
138+void
139+version(void)
140+{
141+ int size;
142+
143+ size = sizeof(versions) / sizeof(versions[0]);
144+
145+ printf("%s ", versions[randomvalue(versions, size)]);
146+}
147+
148+void
149+name(void)
150+{
151+ int size;
152+
153+ size = sizeof(names) / sizeof(names[0]);
154+
155+ printf("%s ", names[randomvalue(names, size)]);
156+}
157+
158+int
159+main(int argc, char *argv[])
160+{
161+ int opt;
162+ if(argc == 1)
163+ osname();
164+
165+ while((opt = getopt(argc, argv, "amnprsv")) != -1){
166+ switch(opt){
167+ case 'm':
168+ arch();
169+ break;
170+ case 'p':
171+ arch();
172+ break;
173+ case 's':
174+ osname();
175+ break;
176+ case 'r':
177+ release();
178+ break;
179+ case 'v':
180+ version();
181+ break;
182+ case 'n':
183+ name();
184+ break;
185+ case 'a':
186+ osname();
187+ name();
188+ release();
189+ version();
190+ arch();
191+ break;
192+ default:
193+ printf("usage: uname [-amnprsv]\n");
194+ return 1;
195+ }
196+ }
197+
198+ printf("\n");
199+
200+ return 0;
201 }