2013-11-24 44 views
1

我必须为Yahtzee程序创建一个设备驱动程序,该程序返回一个随机数1-6。我对Linux非常陌生,并且对编程感到不舒服。我不断收到get_random_bytes函数的错误。它说,错误:函数“get_random_bytes”的隐式声明这是到目前为止我的代码:linux get_random_bytes错误:函数的隐式声明

static ssize_t dice_driver_read(struct file * file, char * buf, 
         size_t count, loff_t *ppos) 
    { 

    unsigned char i; 
    int len = 1; 
    get_random_bytes(&i, sizeof(char)); 

    // char *dice_driver_str = "Hello, world!\n"; 
    // int len = strlen(dice_driver_str); /* Don't include the null byte. */ 
    /* 
    * We only support reading the whole string at once. 
    */ 
if (count < len){ 
      return -EINVAL;} 
    /* 
    * If file position is non-zero, then assume the string has 
    * been read and indicate there is no more data to be read. 
    */ 
if (*ppos != 0){ 
      return 0;} 
    /* 
    * Besides copying the string to the user provided buffer, 
    * this function also checks that the user has permission to 
    * write to the buffer, that it is mapped, etc. 
    */ 

    if (copy_to_user(buf, i, 1)) 
      {return -EINVAL;} 
    /* 
    * Tell the user how much data we wrote. 
    */ 
    *ppos = len; 

    return len; 
    } 

如果有人能指出我为什么发生这种情况,我将不胜感激。这也是来自hello世界代码,所以额外的东西是从那里。由于

回答

2

看起来你并没有包含linux/random.h:

#include <linux/random.h> 
+0

亚克西......感谢您的帮助 –

相关问题