Browse code

cl_rndnum(): use open()

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@325 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/02/23 08:46:03
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Feb 23 00:43:44 CET 2004 (tk)
2
+---------------------------------
3
+  * libclamav: cl_rndnum: do not use buffered fread() (thanks to Nigel)
4
+
1 5
 Sun Feb 22 22:59:39 GMT 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter: Change the log level TCPwrapper denying
... ...
@@ -81,7 +81,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for
81 81
 dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created
82 82
 dnl (the prefix is a bit different, since we add an extra -target- and -host-)
83 83
 dnl 
84
-dnl @version: $Id: aclocal.m4,v 1.22 2004/02/21 15:08:38 kojm Exp $
84
+dnl @version: $Id: aclocal.m4,v 1.23 2004/02/22 23:46:02 kojm Exp $
85 85
 dnl @author Guido Draheim <guidod@gmx.de>                 STATUS: used often
86 86
 
87 87
 AC_DEFUN([AC_CREATE_TARGET_H],
... ...
@@ -4041,7 +4041,7 @@ dnl      AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
4041 4041
 dnl      AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
4042 4042
 dnl
4043 4043
 dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
4044
-dnl @version $Id: aclocal.m4,v 1.22 2004/02/21 15:08:38 kojm Exp $
4044
+dnl @version $Id: aclocal.m4,v 1.23 2004/02/22 23:46:02 kojm Exp $
4045 4045
 dnl
4046 4046
 AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
4047 4047
 [changequote(<<, >>)dnl
... ...
@@ -9573,9 +9573,11 @@ else
9573 9573
   cat >conftest.$ac_ext <<_ACEOF
9574 9574
 #line $LINENO "configure"
9575 9575
 #include "confdefs.h"
9576
-#include <netinet/in.h>
9576
+
9577 9577
 #include <sys/types.h>
9578
+#include <netinet/in.h>
9578 9579
 int main(int argc, char **argv) { in_port_t pt; pt = 0; return pt; }
9580
+
9579 9581
 _ACEOF
9580 9582
 rm -f conftest$ac_exeext
9581 9583
 if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
... ...
@@ -238,10 +238,11 @@ if test x"$tcpw" != xno; then
238 238
 fi
239 239
 
240 240
 # check for in_port_t definition
241
-AC_TRY_RUN([#include <netinet/in.h>
241
+AC_TRY_RUN([
242 242
 #include <sys/types.h>
243
-int main(int argc, char **argv) { in_port_t pt; pt = 0; return pt; }],
244
-AC_DEFINE(HAVE_IN_PORT_T,1,[in_port_t is defined]), AC_MSG_RESULT(in_port_t is not defined))
243
+#include <netinet/in.h>
244
+int main(int argc, char **argv) { in_port_t pt; pt = 0; return pt; }
245
+], AC_DEFINE(HAVE_IN_PORT_T,1,[in_port_t is defined]), AC_MSG_RESULT(in_port_t is not defined))
245 246
 
246 247
 dnl CLAMSCAN_LIBS=""
247 248
 dnl FRESHCLAM_LIBS=""
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 1999-2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 1999 - 2004 Tomasz Kojm <tk@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -263,13 +263,13 @@ unsigned int cl_rndnum(unsigned int max)
263 263
 
264 264
 unsigned int cl_rndnum(unsigned int max)
265 265
 {
266
-	FILE *fd;
266
+	int fd;
267 267
 	unsigned int generated;
268 268
 	char *byte;
269 269
 	int size;
270 270
 
271 271
 
272
-    if((fd = fopen("/dev/urandom", "rb")) == NULL) {
272
+    if((fd = open("/dev/urandom", O_RDONLY)) < 0) {
273 273
 	cli_errmsg("!Can't open /dev/urandom.\n");
274 274
 	return -1;
275 275
     }
... ...
@@ -278,12 +278,12 @@ unsigned int cl_rndnum(unsigned int max)
278 278
     size = sizeof(generated);
279 279
     do {
280 280
 	int bread;
281
-	bread = fread(byte, 1, size, fd);
281
+	bread = read(fd, byte, 1);
282 282
 	size -= bread;
283 283
 	byte += bread;
284 284
     } while(size > 0);
285 285
 
286
-    fclose(fd);
286
+    close(fd);
287 287
     return generated % max;
288 288
 }
289 289
 #endif