[or-cvs] Use fread instead of fgets for binary data

Nick Mathewson nickm at seul.org
Tue Jun 17 20:19:44 UTC 2003


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv13216/src/common

Modified Files:
	crypto.c 
Log Message:
Use fread instead of fgets for binary data

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- crypto.c	14 Jun 2003 01:30:53 -0000	1.22
+++ crypto.c	17 Jun 2003 20:19:41 -0000	1.23
@@ -792,9 +792,8 @@
   static char *filenames[] = { 
     "/dev/srandom", "/dev/urandom", "/dev/random", NULL
   };
-  int i;
+  int i, n;
   char buf[21];
-  char *cp;
   FILE *f;
   
   for (i = 0; filenames[i]; ++i) {
@@ -802,9 +801,9 @@
     if (!f) continue;
     log(LOG_INFO, "Seeding RNG from %s", filenames[i]);
     buf[20]='\xff';
-    cp = fgets(buf, 20, f);
+    n = fread(buf, 1, 20, f);
     fclose(f);
-    if (!cp || buf[20]) {
+    if (n != 20) {
       log(LOG_INFO, "Error reading from entropy source");
       return -1;
     }



More information about the tor-commits mailing list