xiaoxiang781216 commented on code in PR #21902:
URL: https://github.com/apache/nuttx/pull/21902#discussion_r4590337542


##########
libs/libc/stdlib/lib_arc4random.c:
##########
@@ -25,20 +25,64 @@
  ****************************************************************************/
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
 #include <sys/random.h>
 #include <time.h>
 
+#include <nuttx/fs/fs.h>
 #include <nuttx/hashtable.h>
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
 #if defined(CONFIG_DEV_URANDOM) || defined(CONFIG_DEV_RANDOM)
+#  if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+
+/* Read the device through a file of its own: getrandom() would take a
+ * descriptor of the caller and set the errno of the caller.
+ */
+
+static int getrandom_all(FAR void *buf, size_t size, int flags)
+{
+  FAR char *tmp = buf;
+  struct file file;
+  ssize_t nread;
+  int ret;
+
+  ret = file_open(&file, (flags & GRND_RANDOM) != 0 ?

Review Comment:
   why not extract [file_]open/[file_]read to macro? so, the code isn't 
duplicated.



##########
libs/libc/stdlib/lib_arc4random.c:
##########


Review Comment:
   but, what's real problem call open/read in the kernel mode



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to