binutils: Make smart_rename safe too
[deliverable/binutils-gdb.git] / binutils / arsup.c
index a668f270f1a11c3cbc0c77be6419910ece47de7b..8b4437ff41741f670d453a401f4ce7c0356eb3f9 100644 (file)
@@ -345,13 +345,25 @@ ar_save (void)
   else
     {
       char *ofilename = xstrdup (bfd_get_filename (obfd));
+      bfd_boolean skip_stat = FALSE;
+      struct stat target_stat;
+      int ofd = -1;
 
       if (deterministic > 0)
         obfd->flags |= BFD_DETERMINISTIC_OUTPUT;
 
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+      /* It's OK to fail; at worst it will result in SMART_RENAME using a slow
+         copy fallback to write the output.  */
+      ofd = dup (fileno (obfd->iostream));
+      if (lstat (real_name, &target_stat) != 0)
+       skip_stat = TRUE;
+#endif
+
       bfd_close (obfd);
 
-      smart_rename (ofilename, real_name, 0);
+      smart_rename (ofilename, real_name, ofd,
+                   skip_stat ? NULL : &target_stat, 0);
       obfd = 0;
       free (ofilename);
     }
This page took 0.024084 seconds and 4 git commands to generate.