Sun, 21 Aug 2011 23:45:07 +0000
Commit the fix needed for this to build on Windows.
| 3630 | 1 | /* |
| 2 | posix.uname.c - version 1.1 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
23074
diff
changeset
|
3 | Copyright (C) 1999, 2000 |
| 3630 | 4 | Earnie Boyd and assigns |
| 5 | ||
| 6 | Fills the utsname structure with the appropriate values. | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
23074
diff
changeset
|
7 | |
| 3630 | 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU Lesser General Public License as published | |
| 10 | by the Free Software Foundation; either version 2.1, or (at your option) | |
| 11 | any later version. | |
| 12 | ||
| 13 | This program is distributed in the hope that it will be useful, | |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICUALR PURPOSE. See the | |
| 16 | GNU Lesser General Public License for more details. | |
| 17 | ||
| 18 | You should have received a copy of the GNU General Public License | |
| 19 | along with this program; if not, write to the Free Software Foundation, | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15435
diff
changeset
|
20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. |
| 3630 | 21 | */ |
| 22 | ||
| 23 | /* | |
| 24 | Send bug reports to Earnie Boyd <earnie_boyd@yahoo.com> | |
| 25 | */ | |
| 26 | ||
| 27 | #include "utsname.h" | |
| 28 | #include <string.h> | |
| 29 | #include <stdio.h> | |
| 30 | ||
|
32042
95540e6ea463
Commit the fix needed for this to build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31960
diff
changeset
|
31 | #include <glib.h> |
|
95540e6ea463
Commit the fix needed for this to build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31960
diff
changeset
|
32 | |
| 3630 | 33 | /* ANONYMOUS unions and structs are used from the windows header definitions. |
| 34 | These need to be defined for them to work correctly with gcc2.95.2-mingw. */ | |
| 35 | /*#define _ANONYMOUS_STRUCT*/ | |
| 36 | /*#define _ANONYMOUS_UNION*/ | |
| 37 | #include <windows.h> | |
| 23074 | 38 | #ifdef __MINGW32__ |
| 3630 | 39 | #include <_mingw.h> |
| 23074 | 40 | #endif |
| 3630 | 41 | |
| 42 | int | |
| 23074 | 43 | jabber_win32_uname( struct utsname *uts ) |
| 3630 | 44 | { |
| 45 | DWORD sLength; | |
| 46 | OSVERSIONINFO OS_version; | |
| 47 | SYSTEM_INFO System_Info; | |
| 48 | ||
| 49 | /* XXX Should these be in the global runtime */ | |
| 50 | enum WinOS {Win95, Win98, WinNT, unknown}; | |
| 51 | int MingwOS; | |
| 52 | ||
| 53 | memset( uts, 0, sizeof ( *uts ) ); | |
| 54 | OS_version.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); | |
| 55 | ||
| 56 | GetVersionEx ( &OS_version ); | |
| 57 | GetSystemInfo ( &System_Info ); | |
| 58 | ||
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
59 | g_strlcpy( uts->sysname, "WIN32_" , sizeof(uts->sysname)); |
| 3630 | 60 | switch( OS_version.dwPlatformId ) |
| 61 | { | |
| 62 | case VER_PLATFORM_WIN32_NT: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
63 | g_strlcat( uts->sysname, "WinNT", sizeof(uts->sysname) ); |
| 3630 | 64 | MingwOS = WinNT; |
| 65 | break; | |
| 66 | case VER_PLATFORM_WIN32_WINDOWS: | |
| 67 | switch ( OS_version.dwMinorVersion ) | |
| 68 | { | |
| 69 | case 0: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
70 | g_strlcat( uts->sysname, "Win95", sizeof(uts->sysname) ); |
| 3630 | 71 | MingwOS = Win95; |
| 72 | break; | |
| 73 | case 10: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
74 | g_strlcat( uts->sysname, "Win98", sizeof(uts->sysname) ); |
| 3630 | 75 | MingwOS = Win98; |
| 76 | break; | |
| 77 | default: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
78 | g_strlcat( uts->sysname, "Win??", sizeof(uts->sysname) ); |
| 3630 | 79 | MingwOS = unknown; |
| 80 | break; | |
| 81 | } | |
| 82 | break; | |
| 83 | default: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
84 | g_strlcat( uts->sysname, "Win??", sizeof(uts->sysname) ); |
| 3630 | 85 | MingwOS = unknown; |
| 86 | break; | |
| 87 | } | |
| 88 | ||
| 23074 | 89 | #ifdef __MINGW32__ |
| 3630 | 90 | sprintf( uts->version, "%i", __MINGW32_MAJOR_VERSION ); |
| 91 | sprintf( uts->release, "%i", __MINGW32_MINOR_VERSION ); | |
| 23074 | 92 | #endif |
| 3630 | 93 | |
| 94 | switch( System_Info.wProcessorArchitecture ) | |
| 95 | { | |
| 96 | case PROCESSOR_ARCHITECTURE_PPC: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
97 | g_strlcpy( uts->machine, "ppc" , sizeof( uts->machine ) ); |
| 3630 | 98 | break; |
| 99 | case PROCESSOR_ARCHITECTURE_ALPHA: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
100 | g_strlcpy( uts->machine, "alpha" , sizeof( uts->machine ) ); |
| 3630 | 101 | break; |
| 102 | case PROCESSOR_ARCHITECTURE_MIPS: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
103 | g_strlcpy( uts->machine, "mips" , sizeof( uts->machine ) ); |
| 3630 | 104 | break; |
| 105 | case PROCESSOR_ARCHITECTURE_INTEL: | |
| 106 | /* dwProcessorType is only valid in Win95 and Win98 | |
| 107 | wProcessorLevel is only valid in WinNT */ | |
| 108 | switch( MingwOS ) | |
| 109 | { | |
| 110 | case Win95: | |
| 111 | case Win98: | |
| 112 | switch( System_Info.dwProcessorType ) | |
| 113 | { | |
| 114 | case PROCESSOR_INTEL_386: | |
| 115 | case PROCESSOR_INTEL_486: | |
| 116 | case PROCESSOR_INTEL_PENTIUM: | |
| 117 | sprintf( uts->machine, "i%ld", System_Info.dwProcessorType ); | |
| 118 | break; | |
| 119 | default: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
120 | g_strlcpy( uts->machine, "i386" , sizeof( uts->machine ) ); |
| 3630 | 121 | break; |
| 122 | } | |
| 123 | break; | |
| 124 | case WinNT: | |
| 125 | sprintf( uts->machine, "i%d86", System_Info.wProcessorLevel ); | |
| 126 | break; | |
| 127 | default: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
128 | g_strlcpy( uts->machine, "unknown" , sizeof( uts->machine ) ); |
| 3630 | 129 | break; |
| 130 | } | |
| 131 | break; | |
| 132 | default: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
133 | g_strlcpy( uts->machine, "unknown" , sizeof( uts->machine ) ); |
| 3630 | 134 | break; |
| 135 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
23074
diff
changeset
|
136 | |
| 3630 | 137 | sLength = sizeof ( uts->nodename ) - 1; |
| 138 | GetComputerNameA( uts->nodename, &sLength ); | |
| 139 | return 1; | |
| 140 | } | |
| 141 |