mirror of
https://github.com/Hizenberg469/Driver-tutorial.git
synced 2026-04-20 08:52:24 +03:00
27 lines
604 B
C
27 lines
604 B
C
#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;
|
|
} |