comparison src/unexhp9k800.c @ 3025:facf3239ba30

[xemacs-hg @ 2005-10-25 11:16:19 by ben] rename new->new_, convert 'foo to `foo' EmacsFrame.c, ExternalClient.c, ExternalShell.c, chartab.c, cmdloop.c, compiler.h, console.c, database.c, device-msw.c, device-x.c, device.c, doc.c, dragdrop.c, eval.c, event-msw.c, event-stream.c, events.c, extents.c, file-coding.c, fns.c, frame-tty.c, frame.c, gpmevent.c, gutter.c, hash.c, imgproc.c, indent.c, keymap.c, lisp-union.h, macros.c, malloc.c, marker.c, menubar-x.c, menubar.c, mule-charset.c, number.c, process.c, profile.h, ralloc.c, redisplay.c, select-common.h, select.c, syntax.c, sysfile.h, sysproc.h, systime.h, syswindows.h, toolbar.c, tooltalk.c, tparam.c, unexaix.c, unexalpha.c, unexconvex.c, unexec.c, unexhp9k800.c, unexmips.c, unicode.c, window.c: new -> new_. 'foo -> `foo'. lwlib-internal.h: redo assert macros to follow lisp.h and not trigger warnings. lwlib.c, xlwtabs.c: new -> new_.
author ben
date Tue, 25 Oct 2005 11:16:49 +0000
parents 04bc9d2f42c7
children 308d34e9f07d
comparison
equal deleted inserted replaced
3024:b7f26b2f78bd 3025:facf3239ba30
88 88
89 void write_header(int file, struct header *hdr, struct som_exec_auxhdr *auxhdr); 89 void write_header(int file, struct header *hdr, struct som_exec_auxhdr *auxhdr);
90 void read_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr); 90 void read_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr);
91 void save_data_space (int file, struct header *hdr, 91 void save_data_space (int file, struct header *hdr,
92 struct som_exec_auxhdr *auxhdr, int size); 92 struct som_exec_auxhdr *auxhdr, int size);
93 void copy_rest (int old, int new); 93 void copy_rest (int old, int new_);
94 void copy_file (int old, int new, int size); 94 void copy_file (int old, int new_, int size);
95 void update_file_ptrs(int file, struct header *hdr, 95 void update_file_ptrs(int file, struct header *hdr,
96 struct som_exec_auxhdr *auxhdr, 96 struct som_exec_auxhdr *auxhdr,
97 unsigned int location, int offset); 97 unsigned int location, int offset);
98 int calculate_checksum(struct header *hdr); 98 int calculate_checksum(struct header *hdr);
99 99
103 char *old_name, /* name of the old a.out file */ 103 char *old_name, /* name of the old a.out file */
104 uintptr_t UNUSED (new_end_of_text), /* ptr to new edata/etext */ 104 uintptr_t UNUSED (new_end_of_text), /* ptr to new edata/etext */
105 uintptr_t UNUSED (dummy1), /* not used by emacs */ 105 uintptr_t UNUSED (dummy1), /* not used by emacs */
106 uintptr_t UNUSED (dummy2)) 106 uintptr_t UNUSED (dummy2))
107 { 107 {
108 int old, new; 108 int old, new_;
109 int old_size, new_size; 109 int old_size, new_size;
110 struct header hdr; 110 struct header hdr;
111 struct som_exec_auxhdr auxhdr; 111 struct som_exec_auxhdr auxhdr;
112 long i; 112 long i;
113 113
120 120
121 /* Open the input and output a.out files */ 121 /* Open the input and output a.out files */
122 old = open (old_name, O_RDONLY); 122 old = open (old_name, O_RDONLY);
123 if (old < 0) 123 if (old < 0)
124 { perror(old_name); exit(1); } 124 { perror(old_name); exit(1); }
125 new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); 125 new_ = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777);
126 if (new < 0) 126 if (new_ < 0)
127 { perror(new_name); exit(1); } 127 { perror(new_name); exit(1); }
128 128
129 /* Read the old headers */ 129 /* Read the old headers */
130 read_header(old, &hdr, &auxhdr); 130 read_header(old, &hdr, &auxhdr);
131 131
139 i = (long) sbrk (0); 139 i = (long) sbrk (0);
140 new_size = i - auxhdr.exec_dmem; 140 new_size = i - auxhdr.exec_dmem;
141 141
142 /* Copy the old file to the new, up to the data space */ 142 /* Copy the old file to the new, up to the data space */
143 lseek(old, 0, 0); 143 lseek(old, 0, 0);
144 copy_file(old, new, auxhdr.exec_dfile); 144 copy_file(old, new_, auxhdr.exec_dfile);
145 145
146 /* Skip the old data segment and write a new one */ 146 /* Skip the old data segment and write a new one */
147 lseek(old, old_size, 1); 147 lseek(old, old_size, 1);
148 save_data_space(new, &hdr, &auxhdr, new_size); 148 save_data_space(new_, &hdr, &auxhdr, new_size);
149 149
150 /* Copy the rest of the file */ 150 /* Copy the rest of the file */
151 copy_rest(old, new); 151 copy_rest(old, new_);
152 152
153 /* Update file pointers since we probably changed size of data area */ 153 /* Update file pointers since we probably changed size of data area */
154 update_file_ptrs(new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size); 154 update_file_ptrs(new_, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size);
155 155
156 /* Save the modified header */ 156 /* Save the modified header */
157 write_header(new, &hdr, &auxhdr); 157 write_header(new_, &hdr, &auxhdr);
158 158
159 /* Close the binary file */ 159 /* Close the binary file */
160 close (old); 160 close (old);
161 close (new); 161 close (new_);
162 return 0; 162 return 0;
163 } 163 }
164 164
165 /* Save current data space in the file, update header. */ 165 /* Save current data space in the file, update header. */
166 166
282 return(checksum); 282 return(checksum);
283 } 283 }
284 284
285 /* Copy size bytes from the old file to the new one. */ 285 /* Copy size bytes from the old file to the new one. */
286 void 286 void
287 copy_file (int old, int new, int size) 287 copy_file (int old, int new_, int size)
288 { 288 {
289 int len; 289 int len;
290 int buffer[8192]; /* word aligned will be faster */ 290 int buffer[8192]; /* word aligned will be faster */
291 291
292 for (; size > 0; size -= len) 292 for (; size > 0; size -= len)
295 if (read (old, buffer, len) != len) 295 if (read (old, buffer, len) != len)
296 { 296 {
297 perror ("Read failure on a.out file"); 297 perror ("Read failure on a.out file");
298 exit (1); 298 exit (1);
299 } 299 }
300 if (write (new, buffer, len) != len) 300 if (write (new_, buffer, len) != len)
301 { 301 {
302 perror ("Write failure in a.out file"); 302 perror ("Write failure in a.out file");
303 exit (1); 303 exit (1);
304 } 304 }
305 } 305 }
306 } 306 }
307 307
308 /* Copy the rest of the file, up to EOF. */ 308 /* Copy the rest of the file, up to EOF. */
309 void 309 void
310 copy_rest (int old, int new) 310 copy_rest (int old, int new_)
311 { 311 {
312 int buffer[4096]; 312 int buffer[4096];
313 int len; 313 int len;
314 314
315 /* Copy bytes until end of file or error */ 315 /* Copy bytes until end of file or error */
316 while ( (len = read(old, buffer, sizeof(buffer))) > 0) 316 while ( (len = read(old, buffer, sizeof(buffer))) > 0)
317 if (write(new, buffer, len) != len) break; 317 if (write(new_, buffer, len) != len) break;
318 318
319 if (len != 0) 319 if (len != 0)
320 { perror("Unable to copy the rest of the file"); exit(1); } 320 { perror("Unable to copy the rest of the file"); exit(1); }
321 } 321 }
322 322