]> code.delx.au - gnu-emacs/blobdiff - src/unexcoff.c
* src/fileio.c (Fmake_temp_name): Doc tweaks.
[gnu-emacs] / src / unexcoff.c
index 6b2a3336c8a99c8bb16af05e808877f3b90c040d..0cb72d9dcd2a21d4b10ed446aa979d4c7db7b3ec 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1985-1988, 1992-1994, 2001-2013 Free Software
+/* Copyright (C) 1985-1988, 1992-1994, 2001-2015 Free Software
  * Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -65,6 +65,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <crt0.h>   /* for _crt0_startup_flags and its bits */
 #include <sys/exceptn.h>
 static int save_djgpp_startup_flags;
+#include <libc/atexit.h>
+static struct __atexit *save_atexit_ptr;
 #define filehdr external_filehdr
 #define scnhdr external_scnhdr
 #define syment external_syment
@@ -82,7 +84,7 @@ struct aouthdr
   unsigned long                text_start;/* base of text used for this file */
   unsigned long                data_start;/* base of data used for this file */
 };
-#endif /* not MSDOS */
+#endif /* MSDOS */
 #else  /* not HAVE_COFF_H */
 #include <a.out.h>
 #endif /* not HAVE_COFF_H */
@@ -127,9 +129,10 @@ static int pagemask;
 static void
 report_error (const char *file, int fd)
 {
+  int err = errno;
   if (fd)
     emacs_close (fd);
-  report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
+  report_file_errno ("Cannot unexec", build_string (file), err);
 }
 
 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
@@ -367,6 +370,12 @@ copy_text_and_data (int new, int a_out)
      and which might change the way that dumped Emacs works.  */
   save_djgpp_startup_flags = _crt0_startup_flags;
   _crt0_startup_flags &= ~(_CRT0_FLAG_NO_LFN | _CRT0_FLAG_NEARPTR);
+
+  /* Zero out the 'atexit' chain in the dumped executable, to avoid
+     calling the atexit functions twice.  (emacs.c:main installs an
+     atexit function.)  */
+  save_atexit_ptr = __atexit_ptr;
+  __atexit_ptr = NULL;
 #endif
 
   lseek (new, (long) text_scnptr, 0);
@@ -385,6 +394,9 @@ copy_text_and_data (int new, int a_out)
 
   /* Restore the startup flags.  */
   _crt0_startup_flags = save_djgpp_startup_flags;
+
+  /* Restore the atexit chain.  */
+  __atexit_ptr = save_atexit_ptr;
 #endif