60 #define _XOPEN_SOURCE 500
72 #ifdef OPENSSL_SYS_VMS
75 #ifndef NO_SYS_TYPES_H
76 # include <sys/types.h>
78 #ifndef OPENSSL_NO_POSIX_IO
79 # include <sys/stat.h>
86 #define fdopen _fdopen
91 #define RAND_DATA 1024
93 #ifdef OPENSSL_SYS_VMS
96 static FILE *(*
const vms_fopen)(
const char *,
const char *, ...) =
97 (FILE *(*)(
const char *,
const char *, ...))fopen;
98 #define VMS_OPEN_ATTRS "shr=get,put,upd,del","ctx=bin,stm","rfm=stm","rat=none","mrs=0"
112 #ifndef OPENSSL_NO_POSIX_IO
118 if (file == NULL)
return(0);
120 #ifndef OPENSSL_NO_POSIX_IO
127 memset(&sb, 0,
sizeof(sb));
129 if (stat(file,&sb) < 0)
return(0);
132 if (bytes == 0)
return(ret);
134 #ifdef OPENSSL_SYS_VMS
135 in=vms_fopen(file,
"rb",VMS_OPEN_ATTRS);
139 if (in == NULL)
goto err;
140 #if defined(S_IFBLK) && defined(S_IFCHR) && !defined(OPENSSL_NO_POSIX_IO)
141 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
146 bytes = (bytes == -1) ? 2048 : bytes;
147 #ifndef OPENSSL_NO_SETVBUF_IONBF
148 setvbuf(in, NULL, _IONBF, 0);
170 if (bytes <= 0)
break;
182 int i,ret=0,rand_err=0;
185 #ifndef OPENSSL_NO_POSIX_IO
190 #if defined(S_ISBLK) && defined(S_ISCHR)
191 if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
203 #if defined(O_CREAT) && !defined(OPENSSL_NO_POSIX_IO) && !defined(OPENSSL_SYS_VMS)
210 int fd = open(file, O_WRONLY|O_CREAT|
O_BINARY, 0600);
212 out = fdopen(fd,
"wb");
216 #ifdef OPENSSL_SYS_VMS
236 out = vms_fopen(file,
"rb+",VMS_OPEN_ATTRS);
238 out = vms_fopen(file,
"wb",VMS_OPEN_ATTRS);
241 out = fopen(file,
"wb");
243 if (out == NULL)
goto err;
255 i=fwrite(buf,1,i,out);
268 return (rand_err ? -1 : ret);
279 s=getenv(
"RANDFILE");
280 if (s != NULL && *s && strlen(s) + 1 < size)
295 if (s && *s && strlen(s)+strlen(
RFILE)+2 < size)
298 #ifndef OPENSSL_SYS_VMS
316 if (
BUF_strlcpy(buf,
"/dev/arandom",size) >= size) {
319 if (stat(buf,&sb) == -1)
320 if (
BUF_strlcpy(buf,
"/dev/arandom",size) >= size) {