diff options
author | Ron Yorston <rmy@pobox.com> | 2012-02-08 16:12:35 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-02-09 11:52:53 +0000 |
commit | 6e29c121e0afdcfceb1418c2faa6ed070a358f71 (patch) | |
tree | ec27cd8779dfc323d1ae0583b89710af47d83a0f | |
parent | e8ee6096339c6226ee776a945a271a023b8fe0f8 (diff) | |
download | busybox-w32-6e29c121e0afdcfceb1418c2faa6ed070a358f71.tar.gz busybox-w32-6e29c121e0afdcfceb1418c2faa6ed070a358f71.tar.bz2 busybox-w32-6e29c121e0afdcfceb1418c2faa6ed070a358f71.zip |
Implementation of uname for WIN32
-rw-r--r-- | coreutils/uname.c | 8 | ||||
-rw-r--r-- | win32/Kbuild | 1 | ||||
-rw-r--r-- | win32/sys/utsname.h | 66 | ||||
-rw-r--r-- | win32/uname.c | 50 |
4 files changed, 125 insertions, 0 deletions
diff --git a/coreutils/uname.c b/coreutils/uname.c index d1c50e222..c259b1771 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c | |||
@@ -56,7 +56,11 @@ typedef struct { | |||
56 | struct utsname name; | 56 | struct utsname name; |
57 | char processor[sizeof(((struct utsname*)NULL)->machine)]; | 57 | char processor[sizeof(((struct utsname*)NULL)->machine)]; |
58 | char platform[sizeof(((struct utsname*)NULL)->machine)]; | 58 | char platform[sizeof(((struct utsname*)NULL)->machine)]; |
59 | #if ENABLE_PLATFORM_MINGW32 | ||
60 | char os[sizeof("MS/Windows")]; | ||
61 | #else | ||
59 | char os[sizeof("GNU/Linux")]; | 62 | char os[sizeof("GNU/Linux")]; |
63 | #endif | ||
60 | } uname_info_t; | 64 | } uname_info_t; |
61 | 65 | ||
62 | static const char options[] ALIGN1 = "snrvmpioa"; | 66 | static const char options[] ALIGN1 = "snrvmpioa"; |
@@ -123,7 +127,11 @@ int uname_main(int argc UNUSED_PARAM, char **argv) | |||
123 | #endif | 127 | #endif |
124 | strcpy(uname_info.processor, unknown_str); | 128 | strcpy(uname_info.processor, unknown_str); |
125 | strcpy(uname_info.platform, unknown_str); | 129 | strcpy(uname_info.platform, unknown_str); |
130 | #if ENABLE_PLATFORM_MINGW32 | ||
131 | strcpy(uname_info.os, "MS/Windows"); | ||
132 | #else | ||
126 | strcpy(uname_info.os, "GNU/Linux"); | 133 | strcpy(uname_info.os, "GNU/Linux"); |
134 | #endif | ||
127 | #if 0 | 135 | #if 0 |
128 | /* Fedora does something like this */ | 136 | /* Fedora does something like this */ |
129 | strcpy(uname_info.processor, uname_info.name.machine); | 137 | strcpy(uname_info.processor, uname_info.name.machine); |
diff --git a/win32/Kbuild b/win32/Kbuild index bc005c23a..ef3af7458 100644 --- a/win32/Kbuild +++ b/win32/Kbuild | |||
@@ -11,4 +11,5 @@ lib-$(CONFIG_PLATFORM_MINGW32) += process.o | |||
11 | lib-$(CONFIG_PLATFORM_MINGW32) += regex.o | 11 | lib-$(CONFIG_PLATFORM_MINGW32) += regex.o |
12 | lib-$(CONFIG_WIN32_NET) += net.o | 12 | lib-$(CONFIG_WIN32_NET) += net.o |
13 | lib-$(CONFIG_PLATFORM_MINGW32) += termios.o | 13 | lib-$(CONFIG_PLATFORM_MINGW32) += termios.o |
14 | lib-$(CONFIG_PLATFORM_MINGW32) += uname.o | ||
14 | lib-$(CONFIG_PLATFORM_MINGW32) += winansi.o | 15 | lib-$(CONFIG_PLATFORM_MINGW32) += winansi.o |
diff --git a/win32/sys/utsname.h b/win32/sys/utsname.h new file mode 100644 index 000000000..6f12efd58 --- /dev/null +++ b/win32/sys/utsname.h | |||
@@ -0,0 +1,66 @@ | |||
1 | /* Copyright (C) 1991,92,94,96,97,99,2002 Free Software Foundation, Inc. | ||
2 | This file is part of the GNU C Library. | ||
3 | |||
4 | The GNU C Library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) any later version. | ||
8 | |||
9 | The GNU C Library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with the GNU C Library; if not, write to the Free | ||
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
17 | 02111-1307 USA. */ | ||
18 | |||
19 | /* | ||
20 | * POSIX Standard: 4.4 System Identification <sys/utsname.h> | ||
21 | */ | ||
22 | |||
23 | #ifndef _SYS_UTSNAME_H | ||
24 | #define _SYS_UTSNAME_H 1 | ||
25 | |||
26 | #define _UTSNAME_LENGTH 65 | ||
27 | |||
28 | #ifndef _UTSNAME_SYSNAME_LENGTH | ||
29 | # define _UTSNAME_SYSNAME_LENGTH _UTSNAME_LENGTH | ||
30 | #endif | ||
31 | #ifndef _UTSNAME_NODENAME_LENGTH | ||
32 | # define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH | ||
33 | #endif | ||
34 | #ifndef _UTSNAME_RELEASE_LENGTH | ||
35 | # define _UTSNAME_RELEASE_LENGTH _UTSNAME_LENGTH | ||
36 | #endif | ||
37 | #ifndef _UTSNAME_VERSION_LENGTH | ||
38 | # define _UTSNAME_VERSION_LENGTH _UTSNAME_LENGTH | ||
39 | #endif | ||
40 | #ifndef _UTSNAME_MACHINE_LENGTH | ||
41 | # define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH | ||
42 | #endif | ||
43 | |||
44 | /* Structure describing the system and machine. */ | ||
45 | struct utsname | ||
46 | { | ||
47 | /* Name of the implementation of the operating system. */ | ||
48 | char sysname[_UTSNAME_SYSNAME_LENGTH]; | ||
49 | |||
50 | /* Name of this node on the network. */ | ||
51 | char nodename[_UTSNAME_NODENAME_LENGTH]; | ||
52 | |||
53 | /* Current release level of this implementation. */ | ||
54 | char release[_UTSNAME_RELEASE_LENGTH]; | ||
55 | /* Current version level of this release. */ | ||
56 | char version[_UTSNAME_VERSION_LENGTH]; | ||
57 | |||
58 | /* Name of the hardware type the system is running on. */ | ||
59 | char machine[_UTSNAME_MACHINE_LENGTH]; | ||
60 | }; | ||
61 | |||
62 | /* Put information about the system in NAME. */ | ||
63 | extern int uname (struct utsname *__name); | ||
64 | |||
65 | |||
66 | #endif /* sys/utsname.h */ | ||
diff --git a/win32/uname.c b/win32/uname.c new file mode 100644 index 000000000..1c73d073e --- /dev/null +++ b/win32/uname.c | |||
@@ -0,0 +1,50 @@ | |||
1 | #include "libbb.h" | ||
2 | /* After libbb.h, since it needs sys/types.h on some systems */ | ||
3 | #include <sys/utsname.h> | ||
4 | |||
5 | int uname(struct utsname *name) | ||
6 | { | ||
7 | const char *unk = "unknown"; | ||
8 | OSVERSIONINFOEX os_info; | ||
9 | SYSTEM_INFO sys_info; | ||
10 | DWORD len; | ||
11 | |||
12 | strcpy(name->sysname, "Windows_NT"); | ||
13 | |||
14 | len = sizeof(name->nodename) - 1; | ||
15 | if ( !GetComputerName(name->nodename, &len) ) { | ||
16 | strcpy(name->nodename, unk); | ||
17 | } | ||
18 | |||
19 | memset(&os_info, 0, sizeof(OSVERSIONINFOEX)); | ||
20 | os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | ||
21 | |||
22 | strcpy(name->release, unk); | ||
23 | strcpy(name->version, unk); | ||
24 | if (GetVersionEx(&os_info)) { | ||
25 | sprintf(name->release, "%d.%d", os_info.dwMajorVersion, | ||
26 | os_info.dwMinorVersion); | ||
27 | sprintf(name->version, "%d", os_info.dwBuildNumber); | ||
28 | } | ||
29 | |||
30 | strcpy(name->machine, unk); | ||
31 | GetSystemInfo(&sys_info); | ||
32 | switch (sys_info.wProcessorArchitecture) { | ||
33 | case PROCESSOR_ARCHITECTURE_AMD64: | ||
34 | strcpy(name->machine, "x86_64"); | ||
35 | break; | ||
36 | case PROCESSOR_ARCHITECTURE_IA64: | ||
37 | strcpy(name->machine, "ia64"); | ||
38 | break; | ||
39 | case PROCESSOR_ARCHITECTURE_INTEL: | ||
40 | if (sys_info.wProcessorLevel < 6) { | ||
41 | strcpy(name->machine, "i386"); | ||
42 | } | ||
43 | else { | ||
44 | strcpy(name->machine, "i686"); | ||
45 | } | ||
46 | break; | ||
47 | } | ||
48 | |||
49 | return 0; | ||
50 | } | ||