0
votes

I need to make this user space buffer to zero before copying the string c into the buf How to initialize the buffer to zero.

static ssize_t myread(struct file *file,char __user *buf,size_t len, loff_t  *fops)
{
    printk(KERN_INFO"My read with length %d \n",len);
    len = strlen(c);

    if(copy_to_user(buf,c,len) != 0)
        return -EFAULT;
    else if (*fops > 0)
        return 0;
        else
            *fops += len;
            return len;
}
1

1 Answers

2
votes

use memset

See the manpages for usage, it will set a constant byte to a range of consecutive buf addrs