81
81
# include <sys/stat.h>
88
#define fdopen _fdopen
85
92
#define BUFSIZE 1024
86
93
#define RAND_DATA 1024
95
#ifdef OPENSSL_SYS_VMS
96
/* This declaration is a nasty hack to get around vms' extension to fopen
97
* for passing in sharing options being disabled by our /STANDARD=ANSI89 */
98
static FILE *(*const vms_fopen)(const char *, const char *, ...) =
99
(FILE *(*)(const char *, const char *, ...))fopen;
100
#define VMS_OPEN_ATTRS "shr=get,put,upd,del","ctx=bin,stm","rfm=stm","rat=none","mrs=0"
88
103
/* #define RFILE ".rnd" - defined in ../../e_os.h */
90
105
/* Note that these functions are intended for seed files only.
106
121
RAND_add(&sb,sizeof(sb),0.0);
107
122
if (bytes == 0) return(ret);
124
#ifdef OPENSSL_SYS_VMS
125
in=vms_fopen(file,"rb",VMS_OPEN_ATTRS);
109
127
in=fopen(file,"rb");
110
129
if (in == NULL) goto err;
111
130
#if defined(S_IFBLK) && defined(S_IFCHR)
112
131
if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
127
146
i=fread(buf,1,n,in);
128
147
if (i <= 0) break;
149
RAND_add(buf,i,(double)i);
129
151
/* even if n != i, use the full array */
130
152
RAND_add(buf,n,(double)i);
174
197
out = fdopen(fd, "wb");
201
#ifdef OPENSSL_SYS_VMS
202
/* VMS NOTE: Prior versions of this routine created a _new_
203
* version of the rand file for each call into this routine, then
204
* deleted all existing versions named ;-1, and finally renamed
205
* the current version as ';1'. Under concurrent usage, this
206
* resulted in an RMS race condition in rename() which could
207
* orphan files (see vms message help for RMS$_REENT). With the
208
* fopen() calls below, openssl/VMS now shares the top-level
209
* version of the rand file. Note that there may still be
210
* conditions where the top-level rand file is locked. If so, this
211
* code will then create a new version of the rand file. Without
212
* the delete and rename code, this can result in ascending file
213
* versions that stop at version 32767, and this routine will then
214
* return an error. The remedy for this is to recode the calling
215
* application to avoid concurrent use of the rand file, or
216
* synchronize usage at the application level. Also consider
217
* whether or not you NEED a persistent rand file in a concurrent
221
out = vms_fopen(file,"rb+",VMS_OPEN_ATTRS);
223
out = vms_fopen(file,"wb",VMS_OPEN_ATTRS);
178
226
out = fopen(file,"wb");
179
228
if (out == NULL) goto err;
198
247
if (n <= 0) break;
200
#ifdef OPENSSL_SYS_VMS
201
/* Try to delete older versions of the file, until there aren't
206
tmpf = OPENSSL_malloc(strlen(file) + 4); /* to add ";-1" and a nul */
211
while(delete(tmpf) == 0)
213
rename(file,";1"); /* Make sure it's version 1, or we
214
will reach the limit (32767) at
218
#endif /* OPENSSL_SYS_VMS */
221
251
OPENSSL_cleanse(buf,BUFSIZE);