comparison src/unexalpha.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 376386a54a3c
children 850242ba4a81
comparison
equal deleted inserted replaced
172:a38aed19690b 173:8eaf7971accc
21 21
22 /* Synched up with: FSF 19.31. */ 22 /* Synched up with: FSF 19.31. */
23 23
24 24
25 #include <config.h> 25 #include <config.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
26 #include <sys/types.h> 29 #include <sys/types.h>
27 #include <sys/file.h> 30 #include <sys/file.h>
28 #include <sys/stat.h> 31 #include <sys/stat.h>
29 #include <sys/mman.h> 32 #include <sys/mman.h>
30 #include <stdio.h> 33 #include <stdio.h>
32 #include <filehdr.h> 35 #include <filehdr.h>
33 #include <aouthdr.h> 36 #include <aouthdr.h>
34 #include <scnhdr.h> 37 #include <scnhdr.h>
35 #include <syms.h> 38 #include <syms.h>
36 39
37 static void fatal_unexec (); 40 static void fatal_unexec (char *, char *);
38 static void mark_x (); 41 static void mark_x (char *);
39 42
40 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \ 43 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
41 errno = EEOF; \ 44 errno = EEOF; \
42 if (read (_fd, _buffer, _size) != _size) \ 45 if (read (_fd, _buffer, _size) != _size) \
43 fatal_unexec (_error_message, _error_arg); 46 fatal_unexec (_error_message, _error_arg);
139 exit (1); 142 exit (1);
140 } 143 }
141 144
142 if (nhdr.fhdr.f_opthdr != sizeof (nhdr.aout)) 145 if (nhdr.fhdr.f_opthdr != sizeof (nhdr.aout))
143 { 146 {
144 fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n", 147 fprintf (stderr, "unexec: input a.out header is %d bytes, not %ld.\n",
145 nhdr.fhdr.f_opthdr, sizeof (nhdr.aout)); 148 nhdr.fhdr.f_opthdr, (long) (sizeof (nhdr.aout)));
146 exit (1); 149 exit (1);
147 } 150 }
148 if (nhdr.aout.magic != ZMAGIC) 151 if (nhdr.aout.magic != ZMAGIC)
149 { 152 {
150 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n", 153 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n",
344 "writing header of %s", new_name); 347 "writing header of %s", new_name);
345 348
346 close (old); 349 close (old);
347 close (new); 350 close (new);
348 mark_x (new_name); 351 mark_x (new_name);
352 return 0;
349 } 353 }
350 354
351 355
352 #if 0 356 #if 0
353 357
419 * 423 *
420 * After successfully building the new a.out, mark it executable 424 * After successfully building the new a.out, mark it executable
421 */ 425 */
422 426
423 static void 427 static void
424 mark_x (name) 428 mark_x (char *name)
425 char *name;
426 { 429 {
427 struct stat sbuf; 430 struct stat sbuf;
428 int um = umask (777); 431 int um = umask (777);
429 umask (um); 432 umask (um);
430 if (stat (name, &sbuf) < 0) 433 if (stat (name, &sbuf) < 0)
433 if (chmod (name, sbuf.st_mode) < 0) 436 if (chmod (name, sbuf.st_mode) < 0)
434 fatal_unexec ("setting protection on %s", name); 437 fatal_unexec ("setting protection on %s", name);
435 } 438 }
436 439
437 static void 440 static void
438 fatal_unexec (s, arg) 441 fatal_unexec (char *s, char *arg)
439 char *s;
440 char *arg;
441 { 442 {
442 if (errno == EEOF) 443 if (errno == EEOF)
443 fputs ("unexec: unexpected end of file, ", stderr); 444 fputs ("unexec: unexpected end of file, ", stderr);
444 else 445 else
445 fprintf (stderr, "unexec: %s, ", strerror (errno)); 446 fprintf (stderr, "unexec: %s, ", strerror (errno));