前言
实现
#include <stdio.h>
#include <sys/utsname.h>
#include <string.h>
#include <stdint.h>
#include <linux/version.h>
int main(){
struct utsname u;
if(uname(&u) == 0) {
char *c = strchr(u.release, '-');
uint32_t major = 0, minor = 0, rev = 0;
int rc = sscanf(u.release, "%u.%u.%u", &major, &minor, &rev);
if (rc != 3) {
printf("error");
}
uint32_t version = KERNEL_VERSION(major, minor, rev);
if (version >= KERNEL_VERSION(3,10,0)) {
printf("3.10.0:%u\n", KERNEL_VERSION(3,10,0));
printf("release:%u\n", version);
printf("compatible\n");
}
if (c != NULL) {
*c++ = '\0';
uint16_t patch = (uint16_t)(atoi(c));
printf("patch:%u\n", patch);
}
}
return 0;
}