All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] plugins: Use open()/read() instead of fopen()/fread() on autopair
@ 2013-05-16 16:25 Anderson Lizardo
  2013-05-16 16:25 ` [PATCH BlueZ 2/2] core: Avoid unnecessary gboolean on pincode callback API Anderson Lizardo
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Anderson Lizardo @ 2013-05-16 16:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

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]
---

WARNING: compilation tested only.

 plugins/autopair.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/plugins/autopair.c b/plugins/autopair.c
index 5d90f9d..63f906d 100644
--- a/plugins/autopair.c
+++ b/plugins/autopair.c
@@ -27,6 +27,8 @@
 
 #include <stdbool.h>
 #include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include <bluetooth/bluetooth.h>
 #include <glib.h>
@@ -146,15 +148,19 @@ 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;
-
-	f = fopen("/dev/urandom", "rb");
-	if (f != NULL) {
-		fread(&seed, sizeof(seed), 1, f);
-		fclose(f);
+	unsigned int seed;
+	ssize_t nread = 0;
+	int fd;
+
+	fd = open("/dev/urandom", O_RDONLY);
+	if (fd != -1) {
+		nread = read(fd, &seed, sizeof(seed));
+		close(fd);
 	}
 
+	if (nread < (ssize_t) sizeof(seed))
+		seed = time(NULL);
+
 	srand(seed);
 
 	return btd_register_adapter_driver(&autopair_driver);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-06-13 14:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-16 16:25 [PATCH BlueZ 1/2] plugins: Use open()/read() instead of fopen()/fread() on autopair Anderson Lizardo
2013-05-16 16:25 ` [PATCH BlueZ 2/2] core: Avoid unnecessary gboolean on pincode callback API Anderson Lizardo
2013-05-17  5:14 ` [PATCH BlueZ 1/2] plugins: Use open()/read() instead of fopen()/fread() on autopair Marcel Holtmann
2013-05-17 11:05   ` Anderson Lizardo
2013-05-17 12:07     ` Luiz Augusto von Dentz
2013-05-17 14:31 ` [PATCH BlueZ v2 " Anderson Lizardo
2013-05-17 14:31   ` [PATCH BlueZ 2/2] core: Avoid unnecessary gboolean on pincode callback API Anderson Lizardo
2013-05-20 23:51   ` [PATCH BlueZ v2 1/2] plugins: Use open()/read() instead of fopen()/fread() on autopair Johan Hedberg
2013-05-21  6:10     ` Marcel Holtmann
2013-05-21 11:02     ` Anderson Lizardo
2013-05-21 13:06 ` [PATCH BlueZ v3 " Anderson Lizardo
2013-05-21 13:06   ` [PATCH BlueZ 2/2] core: Avoid unnecessary gboolean on pincode callback API Anderson Lizardo
2013-05-28 13:25   ` [PATCH BlueZ v3 1/2] plugins: Use open()/read() instead of fopen()/fread() on autopair Anderson Lizardo
2013-06-13 14:26     ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.