-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestapp.c
More file actions
49 lines (41 loc) · 1.08 KB
/
testapp.c
File metadata and controls
49 lines (41 loc) · 1.08 KB
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
39
40
41
42
43
44
45
46
47
48
49
/* test_driver.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;
int ret;
char my_buf[4000] = { 0 };
/* fill my buffer with *s */
for(i=0; i<4000; i++) my_buf[i] = '*';
/* open the device for read/write/lseek */
printf("[%d] - Opening device \n", getpid() );
fd = open( "/dev/SAMPLE_DEVIC", O_RDWR );
printf("PID [%d]\n", getpid());
getchar();
/* write the contents of my buffer into the device */
ret = write( fd, my_buf, 4000 );
if(ret==-1)
{
perror("ERROR");
exit(1);
}
/* read 70 characters from 20th character */
lseek( fd, 20, SEEK_SET );
ret=read( fd, my_buf, 70 );
if(ret==-1)
{
perror("TEST");
printf("ERRNO:%d\n",errno);
exit(2);
}
printf("I read this from the device\n%s\n", my_buf);
/* Close the device */
close(fd);
}