From 6e29c121e0afdcfceb1418c2faa6ed070a358f71 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 8 Feb 2012 16:12:35 +0000 Subject: Implementation of uname for WIN32 --- win32/Kbuild | 1 + win32/sys/utsname.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ win32/uname.c | 50 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 win32/sys/utsname.h create mode 100644 win32/uname.c (limited to 'win32') 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 lib-$(CONFIG_PLATFORM_MINGW32) += regex.o lib-$(CONFIG_WIN32_NET) += net.o lib-$(CONFIG_PLATFORM_MINGW32) += termios.o +lib-$(CONFIG_PLATFORM_MINGW32) += uname.o 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 @@ +/* Copyright (C) 1991,92,94,96,97,99,2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* + * POSIX Standard: 4.4 System Identification + */ + +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H 1 + +#define _UTSNAME_LENGTH 65 + +#ifndef _UTSNAME_SYSNAME_LENGTH +# define _UTSNAME_SYSNAME_LENGTH _UTSNAME_LENGTH +#endif +#ifndef _UTSNAME_NODENAME_LENGTH +# define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH +#endif +#ifndef _UTSNAME_RELEASE_LENGTH +# define _UTSNAME_RELEASE_LENGTH _UTSNAME_LENGTH +#endif +#ifndef _UTSNAME_VERSION_LENGTH +# define _UTSNAME_VERSION_LENGTH _UTSNAME_LENGTH +#endif +#ifndef _UTSNAME_MACHINE_LENGTH +# define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH +#endif + +/* Structure describing the system and machine. */ +struct utsname + { + /* Name of the implementation of the operating system. */ + char sysname[_UTSNAME_SYSNAME_LENGTH]; + + /* Name of this node on the network. */ + char nodename[_UTSNAME_NODENAME_LENGTH]; + + /* Current release level of this implementation. */ + char release[_UTSNAME_RELEASE_LENGTH]; + /* Current version level of this release. */ + char version[_UTSNAME_VERSION_LENGTH]; + + /* Name of the hardware type the system is running on. */ + char machine[_UTSNAME_MACHINE_LENGTH]; + }; + +/* Put information about the system in NAME. */ +extern int uname (struct utsname *__name); + + +#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 @@ +#include "libbb.h" +/* After libbb.h, since it needs sys/types.h on some systems */ +#include + +int uname(struct utsname *name) +{ + const char *unk = "unknown"; + OSVERSIONINFOEX os_info; + SYSTEM_INFO sys_info; + DWORD len; + + strcpy(name->sysname, "Windows_NT"); + + len = sizeof(name->nodename) - 1; + if ( !GetComputerName(name->nodename, &len) ) { + strcpy(name->nodename, unk); + } + + memset(&os_info, 0, sizeof(OSVERSIONINFOEX)); + os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + + strcpy(name->release, unk); + strcpy(name->version, unk); + if (GetVersionEx(&os_info)) { + sprintf(name->release, "%d.%d", os_info.dwMajorVersion, + os_info.dwMinorVersion); + sprintf(name->version, "%d", os_info.dwBuildNumber); + } + + strcpy(name->machine, unk); + GetSystemInfo(&sys_info); + switch (sys_info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + strcpy(name->machine, "x86_64"); + break; + case PROCESSOR_ARCHITECTURE_IA64: + strcpy(name->machine, "ia64"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + if (sys_info.wProcessorLevel < 6) { + strcpy(name->machine, "i386"); + } + else { + strcpy(name->machine, "i686"); + } + break; + } + + return 0; +} -- cgit v1.2.3-55-g6feb