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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include "system.h"
#include <rpmlib.h>
#include <rpmmacro.h>
#include <rpmio.h>
extern int _rpmio_debug;
#define _ETC_RPM_PLATFORM "/etc/rpm/platform"
static const char * platform = _ETC_RPM_PLATFORM;
static const char ** platpat = NULL;
static int nplatpat = 0;
static int rpmPlatform(void)
{
char *cpu = NULL, *vendor = NULL, *os = NULL, *gnu = NULL;
char * b = NULL;
ssize_t blen = 0;
int init_platform = 0;
char * p, * pe;
int rc;
rc = rpmioSlurp(platform, &b, &blen);
if (rc || b == NULL || blen <= 0) {
rc = -1;
goto exit;
}
p = b;
for (pe = p; p && *p; p = pe) {
pe = strchr(p, '\n');
if (pe)
*pe++ = '\0';
fprintf(stderr, "--- %s\n", p);
while (*p && isspace(*p))
p++;
if (*p == '\0' || *p == '#')
continue;
if (init_platform) {
char * t = p + strlen(p);
while (--t > p && isspace(*t))
*t = '\0';
if (t > p) {
platpat = xrealloc(platpat, (nplatpat + 2) * sizeof(*platpat));
platpat[nplatpat] = xstrdup(p);
fprintf(stderr, "\tplatpat[%d] \"%s\"\n", nplatpat, platpat[nplatpat]);
nplatpat++;
platpat[nplatpat] = NULL;
}
continue;
}
cpu = p;
vendor = "unknown";
os = "unknown";
gnu = NULL;
while (*p && !(*p == '-' || isspace(*p)))
p++;
if (*p != '\0') *p++ = '\0';
fprintf(stderr, "--- cpu \"%s\"\n", cpu);
vendor = p;
while (*p && !(*p == '-' || isspace(*p)))
p++;
if (*p != '-') {
if (*p != '\0') *p++ = '\0';
os = vendor;
vendor = "unknown";
} else {
if (*p != '\0') *p++ = '\0';
os = p;
while (*p && !(*p == '-' || isspace(*p)))
p++;
if (*p == '-') {
*p++ = '\0';
gnu = p;
while (*p && !(*p == '-' || isspace(*p)))
p++;
}
if (*p != '\0') *p++ = '\0';
}
fprintf(stderr, "--- vendor \"%s\"\n", vendor);
fprintf(stderr, "--- os \"%s\"\n", os);
fprintf(stderr, "--- gnu \"%s\"\n", gnu);
addMacro(NULL, "_host_cpu", NULL, cpu, -1);
addMacro(NULL, "_host_vendor", NULL, vendor, -1);
addMacro(NULL, "_host_os", NULL, os, -1);
platpat = xrealloc(platpat, (nplatpat + 2) * sizeof(*platpat));
platpat[nplatpat] = rpmExpand("%{_host_cpu}-%{_host_vendor}-%{_host_os}", (gnu && *gnu ? "-" : NULL), gnu, NULL);
fprintf(stderr, "\tplatpat[%d] \"%s\"\n", nplatpat, platpat[nplatpat]);
nplatpat++;
platpat[nplatpat] = NULL;
init_platform++;
}
rc = (init_platform ? 0 : -1);
exit:
b = _free(b);
return rc;
}
int main (int argc, const char * argv[])
{
int rc;
_rpmio_debug = 0;
rc = rpmPlatform();
return rc;
}
|