File tree 1 file changed +40
-6
lines changed
1 file changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,26 @@ static rt_uint16_t calc_random(void)
21
21
22
22
static rt_ssize_t random_read (rt_device_t dev , rt_off_t pos , void * buffer , rt_size_t size )
23
23
{
24
- rt_uint16_t rand = calc_random ();
25
- ssize_t ret = sizeof (rand );
26
- rt_memcpy (buffer , & rand , ret );
24
+ rt_uint16_t rand ;
25
+ ssize_t ret = 0 ;
26
+ while (size >= sizeof (rand ))
27
+ {
28
+ /* update rand */
29
+ rand = calc_random ();
30
+
31
+ * (rt_uint16_t * )buffer = rand ;
32
+ buffer = (char * )buffer + sizeof (rand );
33
+ ret += sizeof (rand );
34
+ size -= sizeof (rand );
35
+ }
36
+
37
+ if (size )
38
+ {
39
+ rand = calc_random ();
40
+ memcpy (buffer , & rand , size );
41
+ ret += size ;
42
+ }
43
+
27
44
return ret ;
28
45
}
29
46
@@ -95,9 +112,26 @@ static rt_uint16_t calc_urandom(void)
95
112
96
113
static rt_ssize_t random_uread (rt_device_t dev , rt_off_t pos , void * buffer , rt_size_t size )
97
114
{
98
- rt_uint16_t rand = calc_urandom ();
99
- ssize_t ret = sizeof (rand );
100
- rt_memcpy (buffer , & rand , ret );
115
+ rt_uint16_t rand ;
116
+ ssize_t ret = 0 ;
117
+ while (size >= sizeof (rand ))
118
+ {
119
+ /* update rand */
120
+ rand = calc_urandom ();
121
+
122
+ * (rt_uint16_t * )buffer = rand ;
123
+ buffer = (char * )buffer + sizeof (rand );
124
+ ret += sizeof (rand );
125
+ size -= sizeof (rand );
126
+ }
127
+
128
+ if (size )
129
+ {
130
+ rand = calc_urandom ();
131
+ memcpy (buffer , & rand , size );
132
+ ret += size ;
133
+ }
134
+
101
135
return ret ;
102
136
}
103
137
You can’t perform that action at this time.
0 commit comments