From 9313669d6a2110dab5eab6226440509bc6af9a1e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 15 Sep 2016 20:52:05 +0000 Subject: [PATCH 1/1] Port: Add utsname.h compat for mingw MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 1 + include/babeltrace/compat/utsname-internal.h | 111 +++++++++++++++++++ tests/lib/test_ctf_writer.c | 2 +- 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 include/babeltrace/compat/utsname-internal.h diff --git a/include/Makefile.am b/include/Makefile.am index f00544c0..0ffa35a1 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -89,6 +89,7 @@ noinst_HEADERS = \ babeltrace/compat/time-internal.h \ babeltrace/compat/unistd-internal.h \ babeltrace/compat/utc-internal.h \ + babeltrace/compat/utsname-internal.h \ babeltrace/compat/uuid-internal.h \ babeltrace/compiler-internal.h \ babeltrace/ctf-ir/attributes-internal.h \ diff --git a/include/babeltrace/compat/utsname-internal.h b/include/babeltrace/compat/utsname-internal.h new file mode 100644 index 00000000..8ca4ea7b --- /dev/null +++ b/include/babeltrace/compat/utsname-internal.h @@ -0,0 +1,111 @@ + +#ifndef UTSNAME_H +#define UTSNAME_H + +/* + * Copyright 2011 Martin T. Sandsmark + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef __MINGW32__ + +#include +#include +#include + +#define UTSNAME_LENGTH 257 +struct utsname { + char sysname[UTSNAME_LENGTH]; + char nodename[UTSNAME_LENGTH]; + char release[UTSNAME_LENGTH]; + char version[UTSNAME_LENGTH]; + char machine[UTSNAME_LENGTH]; +}; + +static inline +int uname(struct utsname *name) +{ + OSVERSIONINFO versionInfo; + SYSTEM_INFO sysInfo; + int ret = 0; + + /* Get Windows version info */ + memset(&versionInfo, 0, sizeof(OSVERSIONINFO)); + versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&versionInfo); + + /* Get hardware info */ + ZeroMemory(&sysInfo, sizeof(SYSTEM_INFO)); + GetSystemInfo(&sysInfo); + + /* Fill the sysname */ + strcpy(name->sysname, "Windows"); + + /* Fill the release */ + snprintf(name->release, UTSNAME_LENGTH, "%lu", + versionInfo.dwBuildNumber); + + /* Fill the version */ + snprintf(name->version, UTSNAME_LENGTH, "%lu.%lu", + versionInfo.dwMajorVersion, + versionInfo.dwMinorVersion); + + /* Fill ithe nodename */ + if (gethostname(name->nodename, UTSNAME_LENGTH) != 0) { + if (WSAGetLastError() == WSANOTINITIALISED) { + /* WinSock not initialized */ + WSADATA WSAData; + WSAStartup(MAKEWORD(1, 0), &WSAData); + gethostname(name->nodename, UTSNAME_LENGTH); + WSACleanup(); + } else { + ret = -1; + goto end; + } + } + + /* Fill the machine */ + switch(sysInfo.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + strcpy(name->machine, "x86_64"); + break; + case PROCESSOR_ARCHITECTURE_IA64: + strcpy(name->machine, "ia64"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + strcpy(name->machine, "x86"); + break; + case PROCESSOR_ARCHITECTURE_UNKNOWN: + default: + strcpy(name->machine, "unknown"); + } + +end: + return ret; +} +#else /* __MINGW32__ */ +#include +#endif /* __MINGW32__ */ + +#endif //UTSNAME_H diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index c849ca5e..a7a55b94 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include -- 2.34.1