-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrw_test.c
58 lines (45 loc) · 1.14 KB
/
rw_test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @Author: Izhar Shaikh <izhar>
* @Date: 2017-03-21T14:54:08-04:00
* @Email: izharits@gmail.com
* @Filename: ctest.c
* @Last modified by: izhar
* @Last modified time: 2017-03-21T15:30:14-04:00
* @License: MIT
*/
/*
Basic read/write program
@*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int length, fd1, fd2, rc;
char *nodename = "/dev/mycdrv0";
char message[] = " *** TESTING CHAR/DRIVER ***\n";
length = sizeof(message);
if (argc == 2) {
nodename = argv[1];
}
else {
printf("USAGE:\n\t %s <device-node-name>\n", argv[0]);
return 0;
}
fd1 = open(nodename, O_RDWR);
printf(" opened file descriptor first time = %d\n", fd1);
fd2 = open(nodename, O_RDWR);
printf(" opened file descriptor second time = %d\n", fd2);
rc = write(fd1, message, length);
printf("return code from write = %d on %d, message=%s\n", rc, fd1,
message);
memset(message, 0, length);
rc = read(fd2, message, length);
printf("return code from read = %d on %d, message=%s\n", rc, fd2,
message);
close(fd1);
close(fd2);
exit(0);
}