Fix test: remove hardcoded /tmp path
[babeltrace.git] / include / babeltrace / compat / utsname-internal.h
1
2 #ifndef UTSNAME_H
3 #define UTSNAME_H
4
5 /*
6 * Copyright 2011 Martin T. Sandsmark <sandsmark@samfundet.no>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
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.
18 *
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.
29 */
30
31 #ifdef __MINGW32__
32
33 #include <winsock2.h>
34 #include <windows.h>
35 #include <stdio.h>
36
37 #define UTSNAME_LENGTH 257
38 struct utsname {
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];
44 };
45
46 static inline
47 int uname(struct utsname *name)
48 {
49 OSVERSIONINFO versionInfo;
50 SYSTEM_INFO sysInfo;
51 int ret = 0;
52
53 /* Get Windows version info */
54 memset(&versionInfo, 0, sizeof(OSVERSIONINFO));
55 versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
56 GetVersionEx(&versionInfo);
57
58 /* Get hardware info */
59 ZeroMemory(&sysInfo, sizeof(SYSTEM_INFO));
60 GetSystemInfo(&sysInfo);
61
62 /* Fill the sysname */
63 strcpy(name->sysname, "Windows");
64
65 /* Fill the release */
66 snprintf(name->release, UTSNAME_LENGTH, "%lu",
67 versionInfo.dwBuildNumber);
68
69 /* Fill the version */
70 snprintf(name->version, UTSNAME_LENGTH, "%lu.%lu",
71 versionInfo.dwMajorVersion,
72 versionInfo.dwMinorVersion);
73
74 /* Fill ithe nodename */
75 if (gethostname(name->nodename, UTSNAME_LENGTH) != 0) {
76 if (WSAGetLastError() == WSANOTINITIALISED) {
77 /* WinSock not initialized */
78 WSADATA WSAData;
79 WSAStartup(MAKEWORD(1, 0), &WSAData);
80 gethostname(name->nodename, UTSNAME_LENGTH);
81 WSACleanup();
82 } else {
83 ret = -1;
84 goto end;
85 }
86 }
87
88 /* Fill the machine */
89 switch(sysInfo.wProcessorArchitecture) {
90 case PROCESSOR_ARCHITECTURE_AMD64:
91 strcpy(name->machine, "x86_64");
92 break;
93 case PROCESSOR_ARCHITECTURE_IA64:
94 strcpy(name->machine, "ia64");
95 break;
96 case PROCESSOR_ARCHITECTURE_INTEL:
97 strcpy(name->machine, "x86");
98 break;
99 case PROCESSOR_ARCHITECTURE_UNKNOWN:
100 default:
101 strcpy(name->machine, "unknown");
102 }
103
104 end:
105 return ret;
106 }
107 #else /* __MINGW32__ */
108 #include <sys/utsname.h>
109 #endif /* __MINGW32__ */
110
111 #endif //UTSNAME_H
This page took 0.031323 seconds and 4 git commands to generate.