4 * ----------------------------------------------------------------
7 * Copyright (C) 2003 Mojave Group, Caltech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation,
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Additional permission is given to link this library with the
24 * OpenSSL project's "OpenSSL" library, and with the OCaml runtime,
25 * and you may distribute the linked executables. See the file
26 * LICENSE.libmojave for more details.
28 * Author: Jason Hickey
29 * @email{jyh@cs.caltech.edu}
33 #include <caml/mlvalues.h>
34 #include <caml/alloc.h>
35 #include <caml/memory.h>
36 #include <caml/fail.h>
40 /* Disable some of the warnings */
41 #pragma warning( disable : 4127 4189 4702 4996 )
55 * uname is undefined as far as I know (jyh).
56 * Get most of the info from the environment.
58 static int uname(struct utsname
*name
)
62 OSVERSIONINFO osversion
;
66 /* Ask Win32 for OS info */
67 osversion
.dwOSVersionInfoSize
= sizeof(osversion
);
68 if(GetVersionEx(&osversion
) == 0)
71 /* String version of the osname */
72 osname
= (char *) "unknown";
73 switch (osversion
.dwPlatformId
) {
74 case VER_PLATFORM_WIN32s
:
75 osname
= (char *) "win32s";
77 case VER_PLATFORM_WIN32_WINDOWS
:
78 switch (osversion
.dwMinorVersion
) {
80 osname
= (char *) "Win95";
83 osname
= (char *) "Win98";
86 osname
= (char *) "Win9X";
90 case VER_PLATFORM_WIN32_NT
:
91 osname
= (char *) "WinNT";
96 strcpy(name
->sysname
, osname
);
97 sprintf(name
->version
, "%d.%d", (int) osversion
.dwMajorVersion
, (int) osversion
.dwMinorVersion
);
98 sprintf(name
->release
, "%d %s", (int) osversion
.dwBuildNumber
, osversion
.szCSDVersion
);
101 len
= sizeof(name
->nodename
) - 1;
102 GetComputerNameA(name
->nodename
, &len
);
103 name
->nodename
[len
] = 0;
106 GetSystemInfo(&sysinfo
);
109 switch (sysinfo
.wProcessorArchitecture
) {
110 case PROCESSOR_ARCHITECTURE_INTEL
:
111 if(sysinfo
.dwProcessorType
< 3) /* Shouldn't happen. */
113 else if(sysinfo
.dwProcessorType
> 9) /* P4 */
116 ptype
= sysinfo
.dwProcessorType
;
117 sprintf(name
->machine
, "i%d86", ptype
);
119 case PROCESSOR_ARCHITECTURE_ALPHA
:
120 strcpy(name
->machine
, "alpha");
122 case PROCESSOR_ARCHITECTURE_MIPS
:
123 strcpy(name
->machine
, "mips");
126 strcpy(name
->machine
, "unknown");
135 #include <sys/utsname.h>
140 * Allocate a 5-tuple of strings.
142 value
lm_uname(value x
)
153 result
= alloc_tuple(5);
154 Field(result
, 0) = Val_unit
;
155 Field(result
, 1) = Val_unit
;
156 Field(result
, 2) = Val_unit
;
157 Field(result
, 3) = Val_unit
;
158 Field(result
, 4) = Val_unit
;
160 Field(result
, 0) = copy_string(name
.sysname
);
161 Field(result
, 1) = copy_string(name
.nodename
);
162 Field(result
, 2) = copy_string(name
.release
);
163 Field(result
, 3) = copy_string(name
.version
);
164 Field(result
, 4) = copy_string(name
.machine
);