kernel-helloworld-test

view ktestprogram/kprog.c @ 0:dbbd63da261f

helloworld kernel module and program that reads the /dev/ktest
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 10 May 2017 13:11:31 +0300
parents
children
line source
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <unistd.h>
5 int main(void)
6 {
7 char buf[512];
8 size_t size;
9 int fd;
11 if((fd = open("/dev/ktest", O_RDONLY)) == -1) {
12 fprintf(stderr, "Failed to open device ktest.\n");
13 return 1;
14 }
16 if((size = read(fd, buf, sizeof buf)) == -1) {
17 fprintf(stderr, "Failed to read from device ktest.\n");
19 close(fd);
20 return 1;
21 }
22 printf("num char: %d\n", (int)size);
24 buf[size] = 0;
25 printf("quoting kernel: %s", buf);
26 close(fd);
27 return 0;
28 }