summaryrefslogtreecommitdiffstats
path: root/lib/linux_version.c
blob: f9fbd8dff217821974d2c8cc43df07d56eae7f0a (plain) (blame)
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
#include <stdio.h>
#include <sys/utsname.h>

#include "linux_version.h"

int
get_linux_version (void)
{
	static int kver = -1;
	struct utsname uts;
	int major;
	int minor;
	int teeny;

	if (kver != -1)
		return kver;
	if (uname (&uts))
		kver = 0;
	else if (sscanf (uts.release, "%d.%d.%d", &major, &minor, &teeny) != 3)
		kver = 0;
	else
		kver = KERNEL_VERSION (major, minor, teeny);

	return kver;
}