kernel-helloworld-test

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ktestprogram/kprog.c	Wed May 10 13:11:31 2017 +0300
     1.3 @@ -0,0 +1,28 @@
     1.4 +#include <fcntl.h>
     1.5 +#include <stdio.h>
     1.6 +#include <unistd.h>
     1.7 +
     1.8 +int main(void)
     1.9 +{
    1.10 +	char buf[512];
    1.11 +	size_t size;
    1.12 +	int fd;
    1.13 +
    1.14 +	if((fd = open("/dev/ktest", O_RDONLY)) == -1) {
    1.15 +		fprintf(stderr, "Failed to open device ktest.\n");
    1.16 +		return 1;
    1.17 +	}
    1.18 +
    1.19 +	if((size = read(fd, buf, sizeof buf)) == -1) {
    1.20 +		fprintf(stderr, "Failed to read from device ktest.\n");
    1.21 +
    1.22 +		close(fd);
    1.23 +		return 1;
    1.24 +	}
    1.25 +	printf("num char: %d\n", (int)size);
    1.26 +
    1.27 +	buf[size] = 0;
    1.28 +	printf("quoting kernel: %s", buf);
    1.29 +	close(fd);
    1.30 +	return 0;
    1.31 +}