Typo.
[openssl.git] / crypto / rand / randfile.c
index c4e616077923a3fca2f6e5a881972365b8f0ae8b..bc7d9c58049df58b7ac1a098befff75ffa8eb712 100644 (file)
 # include <sys/stat.h>
 #endif
 
+#ifdef _WIN32
+#define stat   _stat
+#define chmod  _chmod
+#define open   _open
+#define fdopen _fdopen
+#endif
+
 #undef BUFSIZE
 #define BUFSIZE        1024
 #define RAND_DATA 1024
@@ -111,6 +118,14 @@ int RAND_load_file(const char *file, long bytes)
        if (file == NULL) return(0);
 
 #ifndef OPENSSL_NO_POSIX_IO
+#ifdef PURIFY
+       /* struct stat can have padding and unused fields that may not be
+        * initialized in the call to stat(). We need to clear the entire
+        * structure before calling RAND_add() to avoid complaints from
+        * applications such as Valgrind.
+        */
+       memset(&sb, 0, sizeof(sb));
+#endif
        if (stat(file,&sb) < 0) return(0);
        RAND_add(&sb,sizeof(sb),0.0);
 #endif
@@ -129,7 +144,9 @@ int RAND_load_file(const char *file, long bytes)
           * I/O because we will waste system entropy. 
           */
          bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
+#ifndef OPENSSL_NO_SETVBUF_IONBF
          setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */
+#endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
        }
 #endif
        for (;;)
@@ -170,8 +187,8 @@ int RAND_write_file(const char *file)
        
        i=stat(file,&sb);
        if (i != -1) { 
-#if defined(S_IFBLK) && defined(S_IFCHR)
-         if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
+#if defined(S_ISBLK) && defined(S_ISCHR)
+         if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
            /* this file is a device. we don't write back to it. 
             * we "succeed" on the assumption this is some sort 
             * of random device. Otherwise attempting to write to 
@@ -254,7 +271,6 @@ err:
 const char *RAND_file_name(char *buf, size_t size)
        {
        char *s=NULL;
-       int ok = 0;
 #ifdef __OpenBSD__
        struct stat sb;
 #endif
@@ -283,7 +299,6 @@ const char *RAND_file_name(char *buf, size_t size)
                        BUF_strlcat(buf,"/",size);
 #endif
                        BUF_strlcat(buf,RFILE,size);
-                       ok = 1;
                        }
                else
                        buf[0] = '\0'; /* no file name */
@@ -297,7 +312,7 @@ const char *RAND_file_name(char *buf, size_t size)
         * to something hopefully decent if that isn't available. 
         */
 
-       if (!ok)
+       if (!buf[0])
                if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
                        return(NULL);
                }