home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / e20313sr.zip / emacs / 20.3.1 / src / unexecemx.c < prev    next >
C/C++ Source or Header  |  1999-07-31  |  2KB  |  70 lines

  1. /* unexecemx.c
  2.    Copyright (C) 1994-1996 Eberhard Mattes.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21.  
  22. #include "config.h"
  23. #include <fcntl.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/process.h>
  27.  
  28. unexec (new_name, a_name, data_start, bss_start, entry_address)
  29.      char *new_name, *a_name;
  30.      unsigned data_start, bss_start, entry_address;
  31. {
  32.   int fd, rc, extract;
  33.   char emxl_path[512];
  34.  
  35.   if (a_name == 0)
  36.     fatal ("SYMFILE argument of dump-emacs is nil\n");
  37.   fd = open ("emacs.cor", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE);
  38.   if (fd < 0)
  39.     fatal ("Cannot create core dump file\n");
  40.   if (_core (fd) != 0)
  41.     fatal ("Cannot write core dump file\n");
  42.   close (fd);
  43.   extract = 0;
  44.   if (access (a_name, 0) != 0)
  45.     {
  46.       rc = spawnlp (P_WAIT, "emxbind.exe", "emxbind.exe",
  47.                     "-xq", a_name, a_name, 0);
  48.       if (rc == -1)
  49.         fatal ("Cannot run emxbind\n");
  50.       if (rc != 0)
  51.         fatal ("emxbind failed to extract a.out image\n");
  52.       extract = 1;
  53.     }
  54.   if (_path (emxl_path, "emxl.exe") != 0
  55.       && _path (emxl_path, "emx.exe") != 0)
  56.     strcpy (emxl_path, "/emx/bin/emxl.exe");
  57.   rc = spawnlp (P_WAIT, "emxbind.exe", "emxbind.exe",
  58.                 "-bqs", "-h48", "-cemacs.cor",
  59.                 emxl_path, a_name, new_name,
  60.                 "-h40", 0);
  61.   unlink ("emacs.cor");
  62.   if (extract)
  63.     unlink (a_name);
  64.   if (rc == -1)
  65.     fatal ("Cannot run emxbind\n");
  66.   if (rc != 0)
  67.     fatal ("emxbind failed to bind executable\n");
  68.   return 0;
  69. }
  70.