summaryrefslogtreecommitdiff
path: root/core/pacman/replace-i686-by-pentium4-when-architecture-is-auto.patch
blob: 909a52d32a6cb4d2bcebc99703c80fe496406db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 0f0c2cfb..b05c456d 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -18,6 +18,7 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <cpuid.h>
 #include <errno.h>
 #include <limits.h>
 #include <locale.h> /* setlocale */
@@ -401,6 +402,12 @@ int config_add_architecture(char *arch)
 		char *newarch;
 		uname(&un);
 		newarch = strdup(un.machine);
+		if(strcmp(newarch, "i686") == 0) {
+			unsigned int eax, ebx, ecx, edx;
+			__get_cpuid(1, &eax, &ebx, &ecx, &edx);
+			if (ecx & bit_SSE2)
+				newarch = strdup("pentium4");
+		}
 		free(arch);
 		arch = newarch;
 	}
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 7e810127..2a50fa4b 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -26,6 +26,7 @@
 
 #include <stdlib.h> /* atoi */
 #include <stdio.h>
+#include <cpuid.h>
 #include <ctype.h> /* isspace */
 #include <limits.h>
 #include <getopt.h>
@@ -274,8 +275,19 @@ static void setuseragent(void)
 	int len;
 
 	uname(&un);
+	char machine[9];
+	strncpy(machine, un.machine, sizeof machine);
+	machine[sizeof machine-1] = '\0';
+	if(strcmp(machine, "i686") == 0) {
+		int eax, ebx, ecx, edx;
+		__get_cpuid(1, &eax, &ebx, &ecx, &edx);
+		if (ecx & bit_SSE2) {
+			strncpy(machine, "pentium4", sizeof machine);
+			machine[sizeof machine-1] = '\0';
+		}
+	}
 	len = snprintf(agent, 100, "pacman/%s (%s %s) libalpm/%s",
-			PACKAGE_VERSION, un.sysname, un.machine, alpm_version());
+			PACKAGE_VERSION, un.sysname, machine, alpm_version());
 	if(len >= 100) {
 		pm_printf(ALPM_LOG_WARNING, _("HTTP_USER_AGENT truncated\n"));
 	}