mirror of
https://github.com/Hizenberg469/Driver-tutorial.git
synced 2026-04-20 00:42:25 +03:00
Character driver finished
This commit is contained in:
27
character_driver/app_test.c
Normal file
27
character_driver/app_test.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main(){
|
||||
|
||||
int fd, i;
|
||||
ssize_t ret;
|
||||
char my_buf[12] = "Hello world";
|
||||
|
||||
fd = open( "/dev/demo_cdrv", O_RDWR);
|
||||
if(fd < 0){
|
||||
printf("failed acquiring file descriptor return status %d\n", fd);
|
||||
}
|
||||
|
||||
/* Write the contents of my buffer into the device */
|
||||
ret = write(fd, my_buf, 8);
|
||||
ret = read(fd, my_buf, 12);
|
||||
if( ret < 0 )
|
||||
printf("read operation failed with return status %d\n", ret);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user