File: archdetect-m68k-linux.c

package info (click to toggle)
ddetect 1.14
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 736 kB
  • ctags: 112
  • sloc: sh: 872; ansic: 533; makefile: 93
file content (72 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download
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
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>

#include "archdetect.h"

struct map {
	char *model;
	char *subarch;
};

struct map map_model[] = {
	{ "Amiga", "amiga" },
	{ "Atari", "atari" },
	{ "Macintosh", "mac" },
	{ "BVME", "bvme6000" },
	{ "Motorola MVME147", "mvme147" },
	{ "Motorola", "mvme16x" },
	{ "Q40", "q40" },
	{ "Sun 3/160 Series", "sun3" },
	{ "Sun 3/50", "sun3" },
	{ "Sun 3/260 Series", "sun3" },
	{ "Sun 3/110 Series", "sun3" },
	{ "Sun 3/60", "sun3" },
	{ "Sun 3/E", "sun3" },
	{ "Sun 3/460 Series", "sun3x" },
	{ "Sun 3/80", "sun3x" },
	{ NULL, NULL }
};


const char *subarch_analyze(void)
{
	FILE *file;
	char line[1024];
	char model[256];
	char *pos;
	int i;

	file = fopen("/proc/hardware", "r");
	if (file == NULL)
		return "unknown";

	while (fgets(line, sizeof(line), file) != NULL) 
	{
	    if (strstr(line, "Model:") == line)
	    {
	        pos = strchr(line, ':');
		if (pos == NULL)
			   continue;
		while (*++pos && (*pos == ' ' || *pos == '\t'));

		strncpy(model, pos, sizeof(model));
		break;
	    }
	}

	fclose(file);

	for (i = 0; map_model[i].model; i++)
	{
	    if (!strncasecmp(map_model[i].model, model, 
			strlen(map_model[i].model)))
	    {
		return( map_model[i].subarch );
	    }
	}

	return "unknown";
}