comparison src/unexcoff.c @ 109910:adb097c7df58

Clean up unexcoff.c. unexcoff.c (report_error, make_hdr, write_segment) (copy_text_and_data, copy_sym, mark_x, adjust_lnnoptrs, unexec): Convert argument lists and prototypes to ANSI C. (make_hdr, write_segment): Remove unused variables. (unexec): Remove commented-out line. Initialize `new' to shut up compiler warnings.
author Eli Zaretskii <eliz@gnu.org>
date Sun, 22 Aug 2010 18:37:01 +0300
parents 8186d147fb99
children 87dd0fd298be 99084f50aa8e
comparison
equal deleted inserted replaced
109909:a1846ab0dc91 109910:adb097c7df58
82 #ifdef HAVE_COFF_H 82 #ifdef HAVE_COFF_H
83 #include <coff.h> 83 #include <coff.h>
84 #ifdef MSDOS 84 #ifdef MSDOS
85 #include <fcntl.h> /* for O_RDONLY, O_RDWR */ 85 #include <fcntl.h> /* for O_RDONLY, O_RDWR */
86 #include <crt0.h> /* for _crt0_startup_flags and its bits */ 86 #include <crt0.h> /* for _crt0_startup_flags and its bits */
87 #include <sys/exceptn.h>
87 static int save_djgpp_startup_flags; 88 static int save_djgpp_startup_flags;
88 #define filehdr external_filehdr 89 #define filehdr external_filehdr
89 #define scnhdr external_scnhdr 90 #define scnhdr external_scnhdr
90 #define syment external_syment 91 #define syment external_syment
91 #define auxent external_auxent 92 #define auxent external_auxent
126 #ifndef O_RDWR 127 #ifndef O_RDWR
127 #define O_RDWR 2 128 #define O_RDWR 2
128 #endif 129 #endif
129 130
130 131
131 extern char *start_of_data (); /* Start of initialized data */ 132 extern char *start_of_data (void); /* Start of initialized data */
132 133
133 static long block_copy_start; /* Old executable start point */ 134 static long block_copy_start; /* Old executable start point */
134 static struct filehdr f_hdr; /* File header */ 135 static struct filehdr f_hdr; /* File header */
135 static struct aouthdr f_ohdr; /* Optional file header (a.out) */ 136 static struct aouthdr f_ohdr; /* Optional file header (a.out) */
136 long bias; /* Bias to add for growth */ 137 long bias; /* Bias to add for growth */
151 #define ADDR_CORRECT(x) ((char *)(x) - (char*)0) 152 #define ADDR_CORRECT(x) ((char *)(x) - (char*)0)
152 153
153 #include <setjmp.h> 154 #include <setjmp.h>
154 #include "lisp.h" 155 #include "lisp.h"
155 156
156 static 157 static void
157 report_error (file, fd) 158 report_error (const char *file, int fd)
158 char *file;
159 int fd;
160 { 159 {
161 if (fd) 160 if (fd)
162 close (fd); 161 close (fd);
163 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); 162 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
164 } 163 }
165 164
166 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 165 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
167 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 166 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1
168 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 167 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1
169 168
170 static 169 static void
171 report_error_1 (fd, msg, a1, a2) 170 report_error_1 (int fd, const char *msg, int a1, int a2)
172 int fd;
173 char *msg;
174 int a1, a2;
175 { 171 {
176 close (fd); 172 close (fd);
177 error (msg, a1, a2); 173 error (msg, a1, a2);
178 } 174 }
179 175
180 static int make_hdr (); 176 static int make_hdr (int, int, unsigned, unsigned, unsigned,
181 static int copy_text_and_data (); 177 const char *, const char *);
182 static int copy_sym (); 178 static int copy_text_and_data (int, int);
183 static void mark_x (); 179 static int copy_sym (int, int, const char *, const char *);
180 static void mark_x (const char *);
184 181
185 /* **************************************************************** 182 /* ****************************************************************
186 * make_hdr 183 * make_hdr
187 * 184 *
188 * Make the header in the new a.out from the header in core. 185 * Make the header in the new a.out from the header in core.
189 * Modify the text and data sizes. 186 * Modify the text and data sizes.
190 */ 187 */
191 static int 188 static int
192 make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) 189 make_hdr (int new, int a_out, unsigned data_start, unsigned bss_start,
193 int new, a_out; 190 unsigned entry_address, const char *a_name, const char *new_name)
194 unsigned data_start, bss_start, entry_address; 191 {
195 char *a_name;
196 char *new_name;
197 {
198 int tem;
199 auto struct scnhdr f_thdr; /* Text section header */ 192 auto struct scnhdr f_thdr; /* Text section header */
200 auto struct scnhdr f_dhdr; /* Data section header */ 193 auto struct scnhdr f_dhdr; /* Data section header */
201 auto struct scnhdr f_bhdr; /* Bss section header */ 194 auto struct scnhdr f_bhdr; /* Bss section header */
202 auto struct scnhdr scntemp; /* Temporary section header */ 195 auto struct scnhdr scntemp; /* Temporary section header */
203 register int scns; 196 register int scns;
361 354
362 return (0); 355 return (0);
363 356
364 } 357 }
365 358
366 write_segment (new, ptr, end) 359 void
367 int new; 360 write_segment (int new, const char *ptr, const char *end)
368 register char *ptr, *end;
369 { 361 {
370 register int i, nwrite, ret; 362 register int i, nwrite, ret;
371 char buf[80];
372 /* This is the normal amount to write at once. 363 /* This is the normal amount to write at once.
373 It is the size of block that NFS uses. */ 364 It is the size of block that NFS uses. */
374 int writesize = 1 << 13; 365 int writesize = 1 << 13;
375 int pagesize = getpagesize (); 366 int pagesize = getpagesize ();
376 char zeros[1 << 13]; 367 char zeros[1 << 13];
409 * copy_text_and_data 400 * copy_text_and_data
410 * 401 *
411 * Copy the text and data segments from memory to the new a.out 402 * Copy the text and data segments from memory to the new a.out
412 */ 403 */
413 static int 404 static int
414 copy_text_and_data (new, a_out) 405 copy_text_and_data (int new, int a_out)
415 int new, a_out;
416 { 406 {
417 register char *end; 407 register char *end;
418 register char *ptr; 408 register char *ptr;
419 409
420 #ifdef MSDOS 410 #ifdef MSDOS
454 * copy_sym 444 * copy_sym
455 * 445 *
456 * Copy the relocation information and symbol table from the a.out to the new 446 * Copy the relocation information and symbol table from the a.out to the new
457 */ 447 */
458 static int 448 static int
459 copy_sym (new, a_out, a_name, new_name) 449 copy_sym (int new, int a_out, const char *a_name, const char *new_name)
460 int new, a_out;
461 char *a_name, *new_name;
462 { 450 {
463 char page[1024]; 451 char page[1024];
464 int n; 452 int n;
465 453
466 if (a_out < 0) 454 if (a_out < 0)
492 * mark_x 480 * mark_x
493 * 481 *
494 * After successfully building the new a.out, mark it executable 482 * After successfully building the new a.out, mark it executable
495 */ 483 */
496 static void 484 static void
497 mark_x (name) 485 mark_x (const char *name)
498 char *name;
499 { 486 {
500 struct stat sbuf; 487 struct stat sbuf;
501 int um; 488 int um;
502 int new = 0; /* for PERROR */ 489 int new = 0; /* for PERROR */
503 490
533 using the two descriptors already open (WRITEDESC and READDESC). 520 using the two descriptors already open (WRITEDESC and READDESC).
534 Instead of reading one small structure at a time it should use 521 Instead of reading one small structure at a time it should use
535 a reasonable size buffer. But I don't have time to work on such 522 a reasonable size buffer. But I don't have time to work on such
536 things, so I am installing it as submitted to me. -- RMS. */ 523 things, so I am installing it as submitted to me. -- RMS. */
537 524
538 adjust_lnnoptrs (writedesc, readdesc, new_name) 525 int
539 int writedesc; 526 adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
540 int readdesc;
541 char *new_name;
542 { 527 {
543 register int nsyms; 528 register int nsyms;
544 register int new; 529 register int new;
545 struct syment symentry; 530 struct syment symentry;
546 union auxent auxentry; 531 union auxent auxentry;
583 /* **************************************************************** 568 /* ****************************************************************
584 * unexec 569 * unexec
585 * 570 *
586 * driving logic. 571 * driving logic.
587 */ 572 */
588 unexec (new_name, a_name, data_start, bss_start, entry_address) 573 int
589 char *new_name, *a_name; 574 unexec (const char *new_name, const char *a_name,
590 unsigned data_start, bss_start, entry_address; 575 unsigned data_start, unsigned bss_start, unsigned entry_address)
591 { 576 {
592 int new, a_out = -1; 577 int new = -1, a_out = -1;
593 578
594 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) 579 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0)
595 { 580 {
596 PERROR (a_name); 581 PERROR (a_name);
597 } 582 }
605 || copy_sym (new, a_out, a_name, new_name) < 0 590 || copy_sym (new, a_out, a_name, new_name) < 0
606 || adjust_lnnoptrs (new, a_out, new_name) < 0 591 || adjust_lnnoptrs (new, a_out, new_name) < 0
607 ) 592 )
608 { 593 {
609 close (new); 594 close (new);
610 /* unlink (new_name); /* Failed, unlink new a.out */
611 return -1; 595 return -1;
612 } 596 }
613 597
614 close (new); 598 close (new);
615 if (a_out >= 0) 599 if (a_out >= 0)