6 * Copyright 2011 Martin T. Sandsmark <sandsmark@samfundet.no>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #define UTSNAME_LENGTH 257
39 char sysname
[UTSNAME_LENGTH
];
40 char nodename
[UTSNAME_LENGTH
];
41 char release
[UTSNAME_LENGTH
];
42 char version
[UTSNAME_LENGTH
];
43 char machine
[UTSNAME_LENGTH
];
47 int uname(struct utsname
*name
)
49 OSVERSIONINFO versionInfo
;
53 /* Get Windows version info */
54 memset(&versionInfo
, 0, sizeof(OSVERSIONINFO
));
55 versionInfo
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
56 GetVersionEx(&versionInfo
);
58 /* Get hardware info */
59 ZeroMemory(&sysInfo
, sizeof(SYSTEM_INFO
));
60 GetSystemInfo(&sysInfo
);
62 /* Fill the sysname */
63 strcpy(name
->sysname
, "Windows");
65 /* Fill the release */
66 snprintf(name
->release
, UTSNAME_LENGTH
, "%lu",
67 versionInfo
.dwBuildNumber
);
69 /* Fill the version */
70 snprintf(name
->version
, UTSNAME_LENGTH
, "%lu.%lu",
71 versionInfo
.dwMajorVersion
,
72 versionInfo
.dwMinorVersion
);
74 /* Fill ithe nodename */
75 if (gethostname(name
->nodename
, UTSNAME_LENGTH
) != 0) {
76 if (WSAGetLastError() == WSANOTINITIALISED
) {
77 /* WinSock not initialized */
79 WSAStartup(MAKEWORD(1, 0), &WSAData
);
80 gethostname(name
->nodename
, UTSNAME_LENGTH
);
88 /* Fill the machine */
89 switch(sysInfo
.wProcessorArchitecture
) {
90 case PROCESSOR_ARCHITECTURE_AMD64
:
91 strcpy(name
->machine
, "x86_64");
93 case PROCESSOR_ARCHITECTURE_IA64
:
94 strcpy(name
->machine
, "ia64");
96 case PROCESSOR_ARCHITECTURE_INTEL
:
97 strcpy(name
->machine
, "x86");
99 case PROCESSOR_ARCHITECTURE_UNKNOWN
:
101 strcpy(name
->machine
, "unknown");
107 #else /* __MINGW32__ */
108 #include <sys/utsname.h>
109 #endif /* __MINGW32__ */