-
Notifications
You must be signed in to change notification settings - Fork 0
/
write.c
39 lines (29 loc) · 814 Bytes
/
write.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#define BUFFER_LENGTH 256 ///< The buffer length (crude but fine)
int main(int argc, char** argv)
{
int ret, fd;
char* stringToSend;
printf("Starting device test code example...\n");
fd = open(argv[1], O_RDWR);
if (fd < 0){
perror("Failed to open the device...");
return errno;
}
printf("Type in a short string to send to the kernel module:\n");
scanf("%m[^\n]%*c", &stringToSend);
printf("Writing message to the device %ld.\n", strlen(stringToSend));
ret = write(fd, stringToSend, strlen(stringToSend));
if (ret < 0){
perror("Failed to write the message to the device.");
return errno;
}
close(fd);
printf("End of the program\n");
return 0;
}