/* Dump an executable image.
- Copyright (C) 1985-1988, 1999, 2001-2013 Free Software Foundation,
+ Copyright (C) 1985-1988, 1999, 2001-2014 Free Software Foundation,
Inc.
This file is part of GNU Emacs.
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
-#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
static _Noreturn void
report_error (const char *file, int fd)
{
+ int err = errno;
if (fd)
- {
- int failed_errno = errno;
- emacs_close (fd);
- errno = failed_errno;
- }
- 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)
{
PERROR (a_name);
}
- if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
+ if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0777)) < 0)
{
PERROR (new_name);
}
emacs_close (new);
if (a_out >= 0)
emacs_close (a_out);
- mark_x (new_name);
}
/* ****************************************************************
char *ptr;
lseek (new, text_scnptr, SEEK_SET);
- ptr = _text + text_scnptr;
+ ptr = _text;
end = ptr + f_ohdr.tsize;
write_segment (new, ptr, end);
return 0;
}
\f
-/* ****************************************************************
- * mark_x
- *
- * After successfully building the new a.out, mark it executable
- */
-static void
-mark_x (const char *name)
-{
- struct stat sbuf;
- int um;
- int new = 0; /* for PERROR */
-
- um = umask (777);
- umask (um);
- if (stat (name, &sbuf) == -1)
- {
- PERROR (name);
- }
- sbuf.st_mode |= 0111 & ~um;
- if (chmod (name, sbuf.st_mode) == -1)
- PERROR (name);
-}
-\f
static int
adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
{
PERROR (a_name);
}
- p = (int *) (ldrel.l_vaddr + d_reloc);
+ p = (int *) (intptr_t) (ldrel.l_vaddr + d_reloc);
switch (ldrel.l_symndx) {
case SYMNDX_TEXT: