-/* 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.
#include <config.h>
#include "unexec.h"
+#include "lisp.h"
#define PERROR(file) report_error (file, new)
#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
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 */
#include <sys/file.h>
-#include "mem-limits.h"
+extern int etext;
static long block_copy_start; /* Old executable start point */
static struct filehdr f_hdr; /* File header */
static void
report_error (const char *file, int fd)
{
+ int err = errno;
if (fd)
- close (fd);
- report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
+ emacs_close (fd);
+ report_file_errno ("Cannot unexec", build_string (file), err);
}
#define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
static void
report_error_1 (int fd, const char *msg, int a1, int a2)
{
- close (fd);
+ emacs_close (fd);
error (msg, a1, a2);
}
\f
pagemask = getpagesize () - 1;
/* Adjust text/data boundary. */
- data_start = (int) start_of_data ();
+ data_start = (int) DATA_START;
data_start = ADDR_CORRECT (data_start);
data_start = data_start & ~pagemask; /* (Down) to page boundary. */
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);
/* Restore the startup flags. */
_crt0_startup_flags = save_djgpp_startup_flags;
+
+ /* Restore the atexit chain. */
+ __atexit_ptr = save_atexit_ptr;
#endif
#ifdef MSDOS
if ((new = writedesc) < 0)
#else
- if ((new = open (new_name, O_RDWR)) < 0)
+ if ((new = emacs_open (new_name, O_RDWR, 0)) < 0)
#endif
{
PERROR (new_name);
}
}
#ifndef MSDOS
- close (new);
+ emacs_close (new);
#endif
return 0;
}
{
int new = -1, a_out = -1;
- if (a_name && (a_out = open (a_name, O_RDONLY)) < 0)
+ if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0)
{
PERROR (a_name);
}
- if ((new = creat (new_name, 0666)) < 0)
+ if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
{
PERROR (new_name);
}
|| adjust_lnnoptrs (new, a_out, new_name) < 0
)
{
- close (new);
+ emacs_close (new);
return;
}
- close (new);
+ emacs_close (new);
if (a_out >= 0)
- close (a_out);
+ emacs_close (a_out);
mark_x (new_name);
}