summaryrefslogtreecommitdiff
path: root/lib/lanplus/lanplus_crypt_impl.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lanplus/lanplus_crypt_impl.c')
-rw-r--r--lib/lanplus/lanplus_crypt_impl.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/lanplus/lanplus_crypt_impl.c b/lib/lanplus/lanplus_crypt_impl.c
index 3f9679e..d12ad9c 100644
--- a/lib/lanplus/lanplus_crypt_impl.c
+++ b/lib/lanplus/lanplus_crypt_impl.c
@@ -61,13 +61,20 @@ int lanplus_seed_prng(uint32_t bytes)
static FILE *fp = NULL;
size_t i;
randfile = RAND_file_name(buffer, sizeof buffer); /* usu C:\.rnd */
- if ((randfile != NULL) && (fp == NULL)) {
- /*first time, so open/create file*/
- fp = fopen(randfile,"w"); /*create the randfile*/
- if (fp != NULL) {
- i = fwrite(" \n",2,1,fp);
- fclose(fp);
- }
+ if ((randfile != NULL) && (fp == NULL)) {
+ fp = fopen(randfile,"r"); /*check the randfile*/
+ if (fp == NULL) { /*does not exist, create it*/
+ /*first time, so open/create file*/
+ fp = fopen(randfile,"w"); /*create the randfile*/
+ if (fp != NULL) {
+ i = fwrite(" \n",2,1,fp);
+ fclose(fp);
+ } else {
+ printf("seed_prng: cannot create %s file\n",randfile);
+ }
+ } else { /*file opened, so close it*/
+ fclose(fp);
+ }
}
if (verbose > 0)
printf("seed_prng: RAND_file_name = %s, fp=%p\n",randfile,fp);