2 #include <sys/utsname.h>
5 #include "linux_version.h"
7 int get_linux_version (void)
11 int x
= 0, y
= 0, z
= 0;
19 n
= sscanf(uts
.release
, "%d.%d.%d", &x
, &y
, &z
);
23 return kver
= KERNEL_VERSION(x
, y
, z
);
26 #ifdef TEST_PROGRAM_LINUXVERSION
28 int main(int argc
, char *argv
[])
30 int rc
= EXIT_FAILURE
;
33 printf("Linux version: %d\n", get_linux_version());
36 } else if (argc
== 5) {
37 const char *oper
= argv
[1];
39 int x
= atoi(argv
[2]),
42 int kver
= get_linux_version();
43 int uver
= KERNEL_VERSION(x
, y
, z
);
45 if (strcmp(oper
, "==") == 0)
47 else if (strcmp(oper
, "<=") == 0)
49 else if (strcmp(oper
, ">=") == 0)
52 errx(EXIT_FAILURE
, "unsupported operator");
57 printf("not-match [%d %s %d, x.y.z: %d.%d.%d]\n",
58 kver
, oper
, uver
, x
, y
, z
);
60 rc
= rc
? EXIT_SUCCESS
: EXIT_FAILURE
;
63 fprintf(stderr
, "Usage:\n"
64 " %s [<oper> <x> <y> <z>]\n"
65 "supported operators:\n"
67 program_invocation_short_name
);