scull测试时的奇怪问题,谢谢
scull 模块加载后,
测试如下:
[root@localhost myscull]# vi tt
[root@localhost myscull]# cp tt /dev/scull0
cp:是否覆盖“/dev/scull0”? y
[root@localhost myscull]# cat /dev/scull0
This is just a test.
这样结果是对的吧?
不过用下面test.c测试时就出现了错误,不知道是什么原因 ?
结果和测试代码如下,谢谢
[root@localhost myscull]# ./test
Please input a string to write the device
This is just a test.
The value of buf is :This
Read the string from the device...
is ju
================================
test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6 #include <sys/types.h>
7
8 int main()
9 {
10 /*device path*/
11 char path[]= "/dev/scull0 ";
12 char buf[120],p[120]= "what ";
13 int num;
14 int f = open(path,O_RDWR);
15
16 if(f == -1){
17 printf( "device open error!\n ");
18 return 1;
19 }
20
21 printf( "Please input a string to write the device \n ");
22 scanf( "%s ",buf);
23 printf( "The value of buf is :%s\n ",buf);
24 num = write(f,buf,strlen(buf)+1);
25
26 printf( "Read the string from the device...\n ");
27 read(f,p,num);
28