diff options
Diffstat (limited to 'crypto/rand/randfile.c')
| -rw-r--r-- | crypto/rand/randfile.c | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index 236c1b0c5420..89797ec9649d 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -7,13 +7,13 @@ * https://www.openssl.org/source/license.html */ -#if defined (__TANDEM) && defined (_SPT_MODEL_) +#if defined(__TANDEM) && defined(_SPT_MODEL_) /* * These definitions have to come first in SPT due to scoping of the * declarations in c99 associated with SPT use of stat. */ -# include <sys/types.h> -# include <sys/stat.h> +#include <sys/types.h> +#include <sys/stat.h> #endif #include "internal/e_os.h" @@ -29,22 +29,22 @@ #include <openssl/buffer.h> #ifdef OPENSSL_SYS_VMS -# include <unixio.h> +#include <unixio.h> #endif #include <sys/types.h> #ifndef OPENSSL_NO_POSIX_IO -# include <sys/stat.h> -# include <fcntl.h> -# if defined(_WIN32) && !defined(_WIN32_WCE) -# include <windows.h> -# include <io.h> -# define stat _stat -# define chmod _chmod -# define open _open -# define fdopen _fdopen -# define fstat _fstat -# define fileno _fileno -# endif +#include <sys/stat.h> +#include <fcntl.h> +#if defined(_WIN32) && !defined(_WIN32_WCE) +#include <windows.h> +#include <io.h> +#define stat _stat +#define chmod _chmod +#define open _open +#define fdopen _fdopen +#define fstat _fstat +#define fileno _fileno +#endif #endif /* @@ -54,9 +54,9 @@ * would look like ((m) & MASK == TYPE), but since MASK availability * is as questionable, we settle for this poor-man fallback... */ -# if !defined(S_ISREG) -# define S_ISREG(m) ((m) & S_IFREG) -# endif +#if !defined(S_ISREG) +#define S_ISREG(m) ((m) & S_IFREG) +#endif #define RAND_BUF_SIZE 1024 #define RFILE ".rnd" @@ -70,11 +70,10 @@ * This declaration is a nasty hack to get around vms' extension to fopen for * passing in sharing options being disabled by /STANDARD=ANSI89 */ -static __FILE_ptr32 (*const vms_fopen)(const char *, const char *, ...) = - (__FILE_ptr32 (*)(const char *, const char *, ...))fopen; -# define VMS_OPEN_ATTRS \ - "shr=get,put,upd,del","ctx=bin,stm","rfm=stm","rat=none","mrs=0" -# define openssl_fopen(fname, mode) vms_fopen((fname), (mode), VMS_OPEN_ATTRS) +static __FILE_ptr32 (*const vms_fopen)(const char *, const char *, ...) = (__FILE_ptr32 (*)(const char *, const char *, ...))fopen; +#define VMS_OPEN_ATTRS \ + "shr=get,put,upd,del", "ctx=bin,stm", "rfm=stm", "rat=none", "mrs=0" +#define openssl_fopen(fname, mode) vms_fopen((fname), (mode), VMS_OPEN_ATTRS) #endif /* @@ -105,14 +104,14 @@ int RAND_load_file(const char *file, long bytes) if ((in = openssl_fopen(file, "rb")) == NULL) { ERR_raise_data(ERR_LIB_RAND, RAND_R_CANNOT_OPEN_FILE, - "Filename=%s", file); + "Filename=%s", file); return -1; } #ifndef OPENSSL_NO_POSIX_IO if (fstat(fileno(in), &sb) < 0) { ERR_raise_data(ERR_LIB_RAND, RAND_R_INTERNAL_ERROR, - "Filename=%s", file); + "Filename=%s", file); fclose(in); return -1; } @@ -132,8 +131,8 @@ int RAND_load_file(const char *file, long bytes) * temporarily. */ #if defined(OPENSSL_SYS_VMS) && defined(__DECC) -# pragma environment save -# pragma message disable maylosedata2 +#pragma environment save +#pragma message disable maylosedata2 #endif /* * Don't buffer, because even if |file| is regular file, we have @@ -142,7 +141,7 @@ int RAND_load_file(const char *file, long bytes) */ setbuf(in, NULL); #if defined(OPENSSL_SYS_VMS) && defined(__DECC) -# pragma environment restore +#pragma environment restore #endif for (;;) { @@ -193,21 +192,20 @@ int RAND_write_file(const char *file) if (stat(file, &sb) >= 0 && !S_ISREG(sb.st_mode)) { ERR_raise_data(ERR_LIB_RAND, RAND_R_NOT_A_REGULAR_FILE, - "Filename=%s", file); + "Filename=%s", file); return -1; } #endif /* Collect enough random data. */ if (RAND_priv_bytes(buf, (int)sizeof(buf)) != 1) - return -1; + return -1; -#if defined(O_CREAT) && !defined(OPENSSL_NO_POSIX_IO) && \ - !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) +#if defined(O_CREAT) && !defined(OPENSSL_NO_POSIX_IO) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) { -# ifndef O_BINARY -# define O_BINARY 0 -# endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif /* * chmod(..., 0600) is too late to protect the file, permissions * should be restrictive from the start @@ -219,7 +217,7 @@ int RAND_write_file(const char *file) if (out == NULL) { close(fd); ERR_raise_data(ERR_LIB_RAND, RAND_R_CANNOT_OPEN_FILE, - "Filename=%s", file); + "Filename=%s", file); return -1; } } @@ -251,7 +249,7 @@ int RAND_write_file(const char *file) out = openssl_fopen(file, "wb"); if (out == NULL) { ERR_raise_data(ERR_LIB_RAND, RAND_R_CANNOT_OPEN_FILE, - "Filename=%s", file); + "Filename=%s", file); return -1; } @@ -282,8 +280,9 @@ const char *RAND_file_name(char *buf, size_t size) if ((envlen = GetEnvironmentVariableW(var = L"RANDFILE", NULL, 0)) == 0) { use_randfile = 0; if ((envlen = GetEnvironmentVariableW(var = L"HOME", NULL, 0)) == 0 - && (envlen = GetEnvironmentVariableW(var = L"USERPROFILE", - NULL, 0)) == 0) + && (envlen = GetEnvironmentVariableW(var = L"USERPROFILE", + NULL, 0)) + == 0) envlen = GetEnvironmentVariableW(var = L"SYSTEMROOT", NULL, 0); } @@ -293,11 +292,13 @@ const char *RAND_file_name(char *buf, size_t size) WCHAR *val = _alloca(envlen * sizeof(WCHAR)); if (GetEnvironmentVariableW(var, val, envlen) < envlen - && (sz = WideCharToMultiByte(CP_UTF8, 0, val, -1, NULL, 0, - NULL, NULL)) != 0) { + && (sz = WideCharToMultiByte(CP_UTF8, 0, val, -1, NULL, 0, + NULL, NULL)) + != 0) { s = _alloca(sz); if (WideCharToMultiByte(CP_UTF8, 0, val, -1, s, sz, - NULL, NULL) == 0) + NULL, NULL) + == 0) s = NULL; } } |
