- 论坛徽章:
- 0
|
unsigned char kbuf[1024]="hello world!\n";
static ssize_t read_test(struct file *file,char *outbuf,size_t count,loff_t *f_pos)
{
//int left;
printk(KERN_ALERT "read1\n");
int bytes_read=0;
if(verify_area(VERIFY_WRITE,outbuf,count)==-EFAULT)
return -EFAULT;
Message_Ptr=kbuf;
while(count && *Message_Ptr)
{
if(put_user(*(Message_Ptr),outbuf))
return -EINVAL;
Message_Ptr++;
outbuf++;
count--;
bytes_read++;
}
return bytes_read;
}
老师在我的测试程序中加了一段程序
memset(outbuf, 0x32, sizeof(outbuf));
n = read(testdev,outbuf,4096);
printf("read len=%d\n", n);
printf("read: %s\n",outbuf);
说这是在初始读取的outbuf的数值
输出为read len=12
read: hello world!
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222....
我定义的outbuf是4096个字节,输出的字符串应该是4096个字节
memset(outbuf, 0, sizeof(outbuf));
n = read(testdev,outbuf,4096);
printf("read len=%d\n", n);
printf("%s\n",outbuf);
我这样输入的就是正常的hello world!
这是什么原因啊~ |
|