File: linuxinfo.c

package info (click to toggle)
linuxinfo 1.1.8-21
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 348 kB
  • ctags: 49
  • sloc: sh: 1,729; ansic: 564; makefile: 80
file content (78 lines) | stat: -rw-r--r-- 2,081 bytes parent folder | download | duplicates (5)
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
/*

	linuxinfo.c

	Copyright (C) 1998-2000
	All Rights Reserved.

	Alex Buell <alex.buell@munted.org.uk>

	Version	Author	Date		Comments
 	----------------------------------------------------------------------
	1.0.0	AIB	199803??	Initial development
	1.0.2	AIB	199803??	Renamed from sysinfo to linuxinfo
					to avoid infringement with a
					commercial product
	1.0.5	AIB	199803??	Added new MHz field for 2.2.x kernels
	1.0.6	AIB	19980306	Added option for testing
	1.1.3	AIB	1999????	If MHz field not detected, does not
					print it
	1.1.4	AIB	1999????	Added -v for versioning
	1.1.6	AIB	20000405	Updates & changes to linuxinfo
	1.1.7	AIB	20000406	Changed to file descriptors
	
	Modelled on Vince Weaver's Linux_logo 2.10
	
	Prints out a line of information about your system.
	Supports Linux on Intel, Sparc, Alpha, m68k and others.	

*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#include "linuxinfo.h"

int main(int argc, char *argv[])
{
	char ordinals[10][10] = { "Unknown", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };

	struct os_stat os;
	struct hw_stat hw;
	struct lib_stat lib;

	int cpuinfo_fd;

	if (argc > 1)
	{
		if (strcmp(argv[1], "-v") == 0)
		{
			printf("%s %s\n", argv[0], VERSION);
			return -1;
		}
		cpuinfo_fd = open(argv[1], O_RDONLY);
	}
	else
		cpuinfo_fd = open(CPUINFO_FILE, O_RDONLY);

	GetOperatingSystemInfo(&os);
	GetHardwareInfo(cpuinfo_fd, &hw);
	GetSystemLibcInfo(&lib);

	printf("%s %s %s %s\n", os.os_name, os.os_hostname, os.os_version, os.os_revision);

	if (strncmp(hw.hw_megahertz, "?", strlen("?")) == 0)
		printf("%s %s processor%s, %s total bogomips, %sM RAM\n", ordinals[hw.hw_processors], \
			hw.hw_cpuinfo, (hw.hw_processors > 1) ? "s" : "", hw.hw_bogomips, hw.hw_memory);
	else
	{
		printf("%s %s %sMHz processor%s, %s total bogomips, %sM RAM\n", ordinals[hw.hw_processors], \
			hw.hw_cpuinfo, hw.hw_megahertz, (hw.hw_processors > 1) ? "s" : "", hw.hw_bogomips, hw.hw_memory);
	}
	printf("System library %s\n", lib.lib_version);

	close(cpuinfo_fd);
	return 0;
}