X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/37d2e431f35492c14510f9960cac94c2f21b6ecb..35e1f9d9fcbaab51808e05f514e63927f959ae51:/src/unexaix.c diff --git a/src/unexaix.c b/src/unexaix.c index 44a824b8c1..fd36e4a73a 100644 --- a/src/unexaix.c +++ b/src/unexaix.c @@ -1,5 +1,5 @@ /* 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. @@ -42,6 +42,7 @@ what you give them. Help stamp out software-hoarding! */ #include #include "unexec.h" +#include "lisp.h" #define PERROR(file) report_error (file, new) #include @@ -54,7 +55,6 @@ what you give them. Help stamp out software-hoarding! */ #include #include #include -#include #include #include #include @@ -93,13 +93,10 @@ static int pagemask; static _Noreturn void report_error (const char *file, int fd) { + int err = errno; if (fd) - { - int failed_errno = errno; - 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) @@ -110,7 +107,7 @@ static _Noreturn void ATTRIBUTE_FORMAT_PRINTF (2, 3) report_error_1 (int fd, const char *msg, ...) { va_list ap; - close (fd); + emacs_close (fd); va_start (ap, msg); verror (msg, ap); va_end (ap); @@ -132,11 +129,11 @@ unexec (const char *new_name, const char *a_name) { 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, 0777)) < 0) { PERROR (new_name); } @@ -147,14 +144,13 @@ unexec (const char *new_name, const char *a_name) || adjust_lnnoptrs (new, a_out, new_name) < 0 || unrelocate_symbols (new, a_out, a_name, new_name) < 0) { - close (new); + emacs_close (new); return; } - close (new); + emacs_close (new); if (a_out >= 0) - close (a_out); - mark_x (new_name); + emacs_close (a_out); } /* **************************************************************** @@ -381,7 +377,7 @@ copy_text_and_data (int new) char *ptr; lseek (new, text_scnptr, SEEK_SET); - ptr = _text + text_scnptr; + ptr = _text; end = ptr + f_ohdr.tsize; write_segment (new, ptr, end); @@ -468,29 +464,6 @@ copy_sym (int new, int a_out, const char *a_name, const char *new_name) return 0; } -/* **************************************************************** - * 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); -} - static int adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name) { @@ -503,7 +476,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name) if (!lnnoptr || !f_hdr.f_symptr) return 0; - if ((new = open (new_name, O_RDWR)) < 0) + if ((new = emacs_open (new_name, O_RDWR, 0)) < 0) { PERROR (new_name); return -1; @@ -533,7 +506,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name) } } } - close (new); + emacs_close (new); return 0; } @@ -608,7 +581,7 @@ unrelocate_symbols (int new, int a_out, 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: