mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-25 21:24:16 +08:00
plugins: Use open()/read() instead of fopen()/fread() on autopair
open()/read() is more common on BlueZ code. Incidentally, get rid of this compilation error (using gcc 4.6.3): plugins/autopair.c: In function ‘autopair_init’: plugins/autopair.c:154:8: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
This commit is contained in:
parent
cf00b35d29
commit
0743aa5a6f
@ -27,6 +27,8 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <glib.h>
|
||||
@ -146,14 +148,20 @@ static struct btd_adapter_driver autopair_driver = {
|
||||
static int autopair_init(void)
|
||||
{
|
||||
/* Initialize the random seed from /dev/urandom */
|
||||
unsigned int seed = time(NULL);
|
||||
FILE *f;
|
||||
unsigned int seed;
|
||||
int fd;
|
||||
|
||||
f = fopen("/dev/urandom", "rb");
|
||||
if (f != NULL) {
|
||||
fread(&seed, sizeof(seed), 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
ssize_t n;
|
||||
|
||||
n = read(fd, &seed, sizeof(seed));
|
||||
if (n < (ssize_t) sizeof(seed))
|
||||
seed = time(NULL);
|
||||
|
||||
close(fd);
|
||||
} else
|
||||
seed = time(NULL);
|
||||
|
||||
srand(seed);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user