2 * No copyright is claimed. This code is in the public domain; do with
6 #include <sys/utsname.h>
9 #include "linux_version.h"
11 int get_linux_version (void)
15 int x
= 0, y
= 0, z
= 0;
23 n
= sscanf(uts
.release
, "%d.%d.%d", &x
, &y
, &z
);
27 return kver
= KERNEL_VERSION(x
, y
, z
);
30 #ifdef TEST_PROGRAM_LINUXVERSION
32 int main(int argc
, char *argv
[])
34 int rc
= EXIT_FAILURE
;
37 printf("Linux version: %d\n", get_linux_version());
40 } else if (argc
== 5) {
41 const char *oper
= argv
[1];
43 int x
= atoi(argv
[2]),
46 int kver
= get_linux_version();
47 int uver
= KERNEL_VERSION(x
, y
, z
);
49 if (strcmp(oper
, "==") == 0)
51 else if (strcmp(oper
, "<=") == 0)
53 else if (strcmp(oper
, ">=") == 0)
56 errx(EXIT_FAILURE
, "unsupported operator");
61 printf("not-match [%d %s %d, x.y.z: %d.%d.%d]\n",
62 kver
, oper
, uver
, x
, y
, z
);
64 rc
= rc
? EXIT_SUCCESS
: EXIT_FAILURE
;
67 fprintf(stderr
, "Usage:\n"
68 " %s [<oper> <x> <y> <z>]\n"
69 "supported operators:\n"
71 program_invocation_short_name
);