Fix the Win32_rename() function so it correctly
authorDr. Stephen Henson <steve@openssl.org>
Fri, 8 Mar 2002 19:11:15 +0000 (19:11 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 8 Mar 2002 19:11:15 +0000 (19:11 +0000)
returns an error code. Use the same code in Win9X
and NT.

Fix some ca.c options so they work under Win32:
unlink/rename wont work under Win32 unless the file
is closed.

apps/apps.c
apps/ca.c

index 8c9726ebd7b060fc6e28a4feed712a8e03e6cf94..f0c280c38d953a086775c6de386344d626cf00fe 100644 (file)
@@ -333,16 +333,13 @@ void program_name(char *in, char *out, int size)
 #ifdef OPENSSL_SYS_WIN32
 int WIN32_rename(char *from, char *to)
        {
 #ifdef OPENSSL_SYS_WIN32
 int WIN32_rename(char *from, char *to)
        {
-#ifdef OPENSSL_SYS_WINNT
-       int ret;
-/* Note: MoveFileEx() doesn't work under Win95, Win98 */
-
-       ret=MoveFileEx(from,to,MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED);
-       return(ret?0:-1);
-#else
-       unlink(to);
-       return MoveFile(from, to);
-#endif
+       /* Windows rename gives an error if 'to' exists, so delete it
+        * first and ignore file not found errror
+        */
+       if((remove(to) != 0) && (errno != ENOENT))
+               return -1;
+#undef rename
+       return rename(from, to);
        }
 #endif
 
        }
 #endif
 
index f368d39b97c76466e4966760b05a63f504999666..583977718969447b14de8465f1296dc604dc3311 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -1581,6 +1581,10 @@ bad:
 #else
                        strcat(buf[1],"-old");
 #endif
 #else
                        strcat(buf[1],"-old");
 #endif
+                       BIO_free(in);
+                       in = NULL;
+                       BIO_free(out);
+                       out = NULL;
                        if (rename(dbfile,buf[1]) < 0)
                                {
                                BIO_printf(bio_err,"unable to rename %s to %s\n", dbfile, buf[1]);
                        if (rename(dbfile,buf[1]) < 0)
                                {
                                BIO_printf(bio_err,"unable to rename %s to %s\n", dbfile, buf[1]);