file.c revision 1.1 1 /*
2 * Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by Mats O Jansson.
15 * 4. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef LINT
31 static char rcsid[] = "$Id: file.c,v 1.1 1997/03/16 22:23:36 cjs Exp $";
32 #endif
33
34 #include "os.h"
35 #include "common/common.h"
36 #include "common/mopdef.h"
37
38 #ifndef NOAOUT
39 #if defined(__NetBSD__) || defined(__OpenBSD__)
40 #include <sys/exec_aout.h>
41 #endif
42 #if defined(__bsdi__)
43 #define NOAOUT
44 #endif
45 #if defined(__FreeBSD__)
46 #include <sys/imgact_aout.h>
47 #endif
48 #if !defined(MID_VAX)
49 #define MID_VAX 140
50 #endif
51 #endif
52
53 void
54 mopFilePutLX(buf, index, value, cnt)
55 u_char *buf;
56 int index, cnt;
57 u_long value;
58 {
59 int i;
60 for (i = 0; i < cnt; i++) {
61 buf[index+i] = value % 256;
62 value = value / 256;
63 }
64 }
65
66 void
67 mopFilePutBX(buf, index, value, cnt)
68 u_char *buf;
69 int index, cnt;
70 u_long value;
71 {
72 int i;
73 for (i = 0; i < cnt; i++) {
74 buf[index+cnt-1-i] = value % 256;
75 value = value / 256;
76 }
77 }
78
79 u_long
80 mopFileGetLX(buf, index, cnt)
81 u_char *buf;
82 int index, cnt;
83 {
84 u_long ret = 0;
85 int i;
86
87 for (i = 0; i < cnt; i++) {
88 ret = ret*256 + buf[index+cnt-1-i];
89 }
90
91 return(ret);
92 }
93
94 u_long
95 mopFileGetBX(buf, index, cnt)
96 u_char *buf;
97 int index, cnt;
98 {
99 u_long ret = 0;
100 int i;
101
102 for (i = 0; i < cnt; i++) {
103 ret = ret*256 + buf[index+i];
104 }
105
106 return(ret);
107 }
108
109 void
110 mopFileSwapX(buf, index, cnt)
111 u_char *buf;
112 int index, cnt;
113 {
114 int i;
115 u_char c;
116
117 for (i = 0; i < (cnt / 2); i++) {
118 c = buf[index+i];
119 buf[index+i] = buf[index+cnt-1-i];
120 buf[index+cnt-1-i] = c;
121 }
122
123 }
124
125 int
126 CheckMopFile(fd)
127 int fd;
128 {
129 u_char header[512];
130 short image_type;
131
132 if (read(fd, header, 512) != 512)
133 return(-1);
134
135 (void)lseek(fd, (off_t) 0, SEEK_SET);
136
137 image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
138 header[IHD_W_ALIAS]);
139
140 switch(image_type) {
141 case IHD_C_NATIVE: /* Native mode image (VAX) */
142 case IHD_C_RSX: /* RSX image produced by TKB */
143 case IHD_C_BPA: /* BASIC plus analog */
144 case IHD_C_ALIAS: /* Alias */
145 case IHD_C_CLI: /* Image is CLI */
146 case IHD_C_PMAX: /* PMAX system image */
147 case IHD_C_ALPHA: /* ALPHA system image */
148 break;
149 default:
150 return(-1);
151 }
152
153 return(0);
154 }
155
156 int
157 GetMopFileInfo(fd, load, xfr)
158 int fd;
159 u_long *load, *xfr;
160 {
161 u_char header[512];
162 short image_type;
163 u_long load_addr, xfr_addr, isd, iha, hbcnt, isize;
164
165 if (read(fd, header, 512) != 512)
166 return(-1);
167
168 image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
169 header[IHD_W_ALIAS]);
170
171 switch(image_type) {
172 case IHD_C_NATIVE: /* Native mode image (VAX) */
173 isd = (header[IHD_W_SIZE+1]*256 +
174 header[IHD_W_SIZE]);
175 iha = (header[IHD_W_ACTIVOFF+1]*256 +
176 header[IHD_W_ACTIVOFF]);
177 hbcnt = (header[IHD_B_HDRBLKCNT]);
178 isize = (header[isd+ISD_W_PAGCNT+1]*256 +
179 header[isd+ISD_W_PAGCNT]) * 512;
180 load_addr = ((header[isd+ISD_V_VPN+1]*256 +
181 header[isd+ISD_V_VPN]) & ISD_M_VPN)
182 * 512;
183 xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
184 header[iha+IHA_L_TFRADR1+2]*0x10000 +
185 header[iha+IHA_L_TFRADR1+1]*0x100 +
186 header[iha+IHA_L_TFRADR1]) & 0x7fffffff;
187 #ifdef INFO
188 printf("Native Image (VAX)\n");
189 printf("Header Block Count: %d\n",hbcnt);
190 printf("Image Size: %08x\n",isize);
191 printf("Load Address: %08x\n",load_addr);
192 printf("Transfer Address: %08x\n",xfr_addr);
193 #endif
194 break;
195 case IHD_C_RSX: /* RSX image produced by TKB */
196 hbcnt = header[L_BBLK+1]*256 + header[L_BBLK];
197 isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64;
198 load_addr = header[L_BSA+1]*256 + header[L_BSA];
199 xfr_addr = header[L_BXFR+1]*256 + header[L_BXFR];
200 #ifdef INFO
201 printf("RSX Image\n");
202 printf("Header Block Count: %d\n",hbcnt);
203 printf("Image Size: %08x\n",isize);
204 printf("Load Address: %08x\n",load_addr);
205 printf("Transfer Address: %08x\n",xfr_addr);
206 #endif
207 break;
208 case IHD_C_BPA: /* BASIC plus analog */
209 #ifdef INFO
210 printf("BASIC-Plus Image, not supported\n");
211 #endif
212 return(-1);
213 break;
214 case IHD_C_ALIAS: /* Alias */
215 #ifdef INFO
216 printf("Alias, not supported\n");
217 #endif
218 return(-1);
219 break;
220 case IHD_C_CLI: /* Image is CLI */
221 #ifdef INFO
222 printf("CLI, not supported\n");
223 #endif
224 return(-1);
225 break;
226 case IHD_C_PMAX: /* PMAX system image */
227 isd = (header[IHD_W_SIZE+1]*256 +
228 header[IHD_W_SIZE]);
229 iha = (header[IHD_W_ACTIVOFF+1]*256 +
230 header[IHD_W_ACTIVOFF]);
231 hbcnt = (header[IHD_B_HDRBLKCNT]);
232 isize = (header[isd+ISD_W_PAGCNT+1]*256 +
233 header[isd+ISD_W_PAGCNT]) * 512;
234 load_addr = (header[isd+ISD_V_VPN+1]*256 +
235 header[isd+ISD_V_VPN]) * 512;
236 xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
237 header[iha+IHA_L_TFRADR1+2]*0x10000 +
238 header[iha+IHA_L_TFRADR1+1]*0x100 +
239 header[iha+IHA_L_TFRADR1]);
240 #ifdef INFO
241 printf("PMAX Image \n");
242 printf("Header Block Count: %d\n",hbcnt);
243 printf("Image Size: %08x\n",isize);
244 printf("Load Address: %08x\n",load_addr);
245 printf("Transfer Address: %08x\n",xfr_addr);
246 #endif
247 break;
248 case IHD_C_ALPHA: /* ALPHA system image */
249 isd = (header[EIHD_L_ISDOFF+3]*0x1000000 +
250 header[EIHD_L_ISDOFF+2]*0x10000 +
251 header[EIHD_L_ISDOFF+1]*0x100 +
252 header[EIHD_L_ISDOFF]);
253 hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 +
254 header[EIHD_L_HDRBLKCNT+2]*0x10000 +
255 header[EIHD_L_HDRBLKCNT+1]*0x100 +
256 header[EIHD_L_HDRBLKCNT]);
257 isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 +
258 header[isd+EISD_L_SECSIZE+2]*0x10000 +
259 header[isd+EISD_L_SECSIZE+1]*0x100 +
260 header[isd+EISD_L_SECSIZE]);
261 load_addr = 0;
262 xfr_addr = 0;
263 #ifdef INFO
264 printf("Alpha Image \n");
265 printf("Header Block Count: %d\n",hbcnt);
266 printf("Image Size: %08x\n",isize);
267 printf("Load Address: %08x\n",load_addr);
268 printf("Transfer Address: %08x\n",xfr_addr);
269 #endif
270 break;
271 default:
272 #ifdef INFO
273 printf("Unknown Image (%d)\n",image_type);
274 #endif
275 return(-1);
276 }
277
278 if (load != NULL) {
279 *load = load_addr;
280 }
281
282 if (xfr != NULL) {
283 *xfr = xfr_addr;
284 }
285
286 return(0);
287 }
288
289 #ifndef NOAOUT
290 int
291 getMID(old_mid,new_mid)
292 int old_mid, new_mid;
293 {
294 int mid;
295
296 mid = old_mid;
297
298 switch (new_mid) {
299 case MID_I386:
300 mid = MID_I386;
301 break;
302 #ifdef MID_M68K
303 case MID_M68K:
304 mid = MID_M68K;
305 break;
306 #endif
307 #ifdef MID_M68K4K
308 case MID_M68K4K:
309 mid = MID_M68K4K;
310 break;
311 #endif
312 #ifdef MID_NS32532
313 case MID_NS32532:
314 mid = MID_NS32532;
315 break;
316 #endif
317 /*###323 [cc] for each function it appears in.)%%%*/
318 /*###323 [cc] (Each undeclared identifier is reported only once%%%*/
319 /*###323 [cc] `MID_SPARC' undeclared (first use this function)%%%*/
320 case MID_SPARC:
321 mid = MID_SPARC;
322 break;
323 #ifdef MID_PMAX
324 case MID_PMAX:
325 mid = MID_PMAX;
326 break;
327 #endif
328 #ifdef MID_VAX
329 case MID_VAX:
330 mid = MID_VAX;
331 break;
332 #endif
333 #ifdef MID_ALPHA
334 case MID_ALPHA:
335 mid = MID_ALPHA;
336 break;
337 #endif
338 #ifdef MID_MIPS
339 case MID_MIPS:
340 mid = MID_MIPS;
341 break;
342 #endif
343 #ifdef MID_ARM6
344 case MID_ARM6:
345 mid = MID_ARM6;
346 break;
347 #endif
348 default:
349 /*###352 [cc] syntax error before `}'%%%*/
350 }
351
352 return(mid);
353 }
354
355 int
356 getCLBYTES(mid)
357 int mid;
358 {
359 int clbytes;
360
361 switch (mid) {
362 #ifdef MID_VAX
363 case MID_VAX:
364 clbytes = 1024;
365 break;
366 #endif
367 case MID_I386:
368 #ifdef MID_M68K4K
369 case MID_M68K4K:
370 #endif
371 #ifdef MID_NS32532
372 case MID_NS32532:
373 #endif
374 case MID_SPARC: /* It might be 8192 */
375 #ifdef MID_PMAX
376 case MID_PMAX:
377 #endif
378 #ifdef MID_MIPS
379 case MID_MIPS:
380 #endif
381 #ifdef MID_ARM6
382 case MID_ARM6:
383 #endif
384 clbytes = 4096;
385 break;
386 #ifdef MID_M68K
387 case MID_M68K:
388 #endif
389 #ifdef MID_ALPHA
390 case MID_ALPHA:
391 #endif
392 #if defined(MID_M68K) || defined(MID_ALPHA)
393 clbytes = 8192;
394 break;
395 #endif
396 default:
397 clbytes = 0;
398 }
399
400 return(clbytes);
401 }
402 #endif
403
404 /*###406 [cc] syntax error before `int'%%%*/
405 int
406 CheckAOutFile(fd)
407 int fd;
408 {
409 #ifdef NOAOUT
410 return(-1);
411 #else
412 struct exec ex, ex_swap;
413 int mid = -1;
414
415 /*###416 [cc] `fd' undeclared (first use this function)%%%*/
416 if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
417 return(-1);
418
419 (void)lseek(fd, (off_t) 0, SEEK_SET);
420
421 if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
422 return(-1);
423
424 (void)lseek(fd, (off_t) 0, SEEK_SET);
425
426 mid = getMID(mid, N_GETMID (ex));
427
428 if (mid == -1) {
429 mid = getMID(mid, N_GETMID (ex_swap));
430 }
431
432 if (mid != -1) {
433 return(0);
434 } else {
435 return(-1);
436 }
437 #endif NOAOUT
438 }
439
440 /*###440 [cc] syntax error before `int'%%%*/
441 int
442 GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
443 a_data, a_data_fill, a_bss, a_bss_fill, aout)
444 int fd, *aout;
445 u_long *load, *xfr, *a_text, *a_text_fill;
446 u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
447 {
448 #ifdef NOAOUT
449 return(-1);
450 #else
451 struct exec ex, ex_swap;
452 int mid = -1;
453 u_long magic, clbytes, clofset;
454
455 if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
456 return(-1);
457
458 (void)lseek(fd, (off_t) 0, SEEK_SET);
459
460 if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
461 return(-1);
462
463 mopFileSwapX((u_char *)&ex_swap, 0, 4);
464
465 mid = getMID(mid, N_GETMID (ex));
466
467 if (mid == -1) {
468 mid = getMID(mid, N_GETMID (ex_swap));
469 if (mid != -1) {
470 mopFileSwapX((u_char *)&ex, 0, 4);
471 }
472 }
473
474 if (mid == -1) {
475 return(-1);
476 }
477
478 if (N_BADMAG (ex)) {
479 return(-1);
480 }
481
482 switch (mid) {
483 case MID_I386:
484 #ifdef MID_NS32532
485 case MID_NS32532:
486 #endif
487 #ifdef MID_PMAX
488 case MID_PMAX:
489 #endif
490 #ifdef MID_VAX
491 case MID_VAX:
492 #endif
493 #ifdef MID_ALPHA
494 case MID_ALPHA:
495 #endif
496 #ifdef MID_ARM6
497 case MID_ARM6:
498 #endif
499 ex.a_text = mopFileGetLX((u_char *)&ex_swap, 4, 4);
500 ex.a_data = mopFileGetLX((u_char *)&ex_swap, 8, 4);
501 ex.a_bss = mopFileGetLX((u_char *)&ex_swap, 12, 4);
502 ex.a_syms = mopFileGetLX((u_char *)&ex_swap, 16, 4);
503 ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4);
504 ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4);
505 ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4);
506 break;
507 #ifdef MID_M68K
508 case MID_M68K:
509 #endif
510 #ifdef MID_M68K4K
511 case MID_M68K4K:
512 #endif
513 case MID_SPARC:
514 #ifdef MID_MIPS
515 case MID_MIPS:
516 #endif
517 ex.a_text = mopFileGetBX((u_char *)&ex_swap, 4, 4);
518 ex.a_data = mopFileGetBX((u_char *)&ex_swap, 8, 4);
519 ex.a_bss = mopFileGetBX((u_char *)&ex_swap, 12, 4);
520 ex.a_syms = mopFileGetBX((u_char *)&ex_swap, 16, 4);
521 ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4);
522 ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4);
523 ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4);
524 break;
525 default:
526 /*###525 [cc] syntax error before `}'%%%*/
527 }
528
529 #ifdef INFO
530 printf("a.out image (");
531 switch (N_GETMID (ex)) {
532 case MID_I386:
533 printf("i386");
534 break;
535 #ifdef MID_M68K
536 case MID_M68K:
537 printf("m68k");
538 break;
539 #endif
540 #ifdef MID_M68K4K
541 case MID_M68K4K:
542 printf("m68k 4k");
543 break;
544 #endif
545 #ifdef MID_NS32532
546 case MID_NS32532:
547 printf("pc532");
548 break;
549 #endif
550 case MID_SPARC:
551 printf("sparc");
552 break;
553 #ifdef MID_PMAX
554 case MID_PMAX:
555 printf("pmax");
556 break;
557 #endif
558 #ifdef MID_VAX
559 case MID_VAX:
560 printf("vax");
561 break;
562 #endif
563 #ifdef MID_ALPHA
564 case MID_ALPHA:
565 printf("alpha");
566 break;
567 #endif
568 #ifdef MID_MIPS
569 case MID_MIPS:
570 printf("mips");
571 break;
572 #endif
573 #ifdef MID_ARM6
574 case MID_ARM6:
575 printf("arm32");
576 break;
577 #endif
578 default:
579 }
580 printf(") Magic: ");
581 switch (N_GETMAGIC (ex)) {
582 case OMAGIC:
583 printf("OMAGIC");
584 break;
585 case NMAGIC:
586 printf("NMAGIC");
587 break;
588 case ZMAGIC:
589 printf("ZMAGIC");
590 break;
591 case QMAGIC:
592 printf("QMAGIC");
593 break;
594 default:
595 printf("Unknown %d",N_GETMAGIC (ex));
596 }
597 printf("\n");
598 printf("Size of text: %08x\n",ex.a_text);
599 printf("Size of data: %08x\n",ex.a_data);
600 printf("Size of bss: %08x\n",ex.a_bss);
601 printf("Size of symbol tab: %08x\n",ex.a_syms);
602 printf("Transfer Address: %08x\n",ex.a_entry);
603 printf("Size of reloc text: %08x\n",ex.a_trsize);
604 printf("Size of reloc data: %08x\n",ex.a_drsize);
605 #endif
606 magic = N_GETMAGIC (ex);
607 clbytes = getCLBYTES(mid);
608 clofset = clbytes - 1;
609
610 /*###608 [cc] `load' undeclared (first use this function)%%%*/
611 if (load != NULL) {
612 *load = 0;
613 }
614
615 /*###612 [cc] `xfr' undeclared (first use this function)%%%*/
616 if (xfr != NULL) {
617 *xfr = ex.a_entry;
618 }
619
620 /*###616 [cc] `a_text' undeclared (first use this function)%%%*/
621 if (a_text != NULL) {
622 *a_text = ex.a_text;
623 }
624
625 /*###620 [cc] `a_text_fill' undeclared (first use this function)%%%*/
626 if (a_text_fill != NULL) {
627 if (magic == ZMAGIC || magic == NMAGIC) {
628 *a_text_fill = clbytes - (ex.a_text & clofset);
629 if (*a_text_fill == clbytes) {
630 *a_text_fill = 0;
631 }
632 } else {
633 *a_text_fill = 0;
634 }
635 }
636
637 /*###631 [cc] `a_data' undeclared (first use this function)%%%*/
638 if (a_data != NULL) {
639 *a_data = ex.a_data;
640 }
641
642 /*###635 [cc] `a_data_fill' undeclared (first use this function)%%%*/
643 if (a_data_fill != NULL) {
644 if (magic == ZMAGIC || magic == NMAGIC) {
645 *a_data_fill = clbytes - (ex.a_data & clofset);
646 if (*a_data_fill == clbytes) {
647 *a_data_fill = 0;
648 }
649 } else {
650 *a_data_fill = 0;
651 }
652 }
653
654 /*###646 [cc] `a_bss' undeclared (first use this function)%%%*/
655 if (a_bss != NULL) {
656 *a_bss = ex.a_bss;
657 }
658
659 /*###650 [cc] `a_bss_fill' undeclared (first use this function)%%%*/
660 if (a_bss_fill != NULL) {
661 if (magic == ZMAGIC || magic == NMAGIC) {
662 *a_bss_fill = clbytes - (ex.a_bss & clofset);
663 if (*a_bss_fill == clbytes) {
664 *a_bss_fill = 0;
665 }
666 } else {
667 *a_bss_fill = clbytes -
668 ((ex.a_text+ex.a_data+ex.a_bss) & clofset);
669 if (*a_text_fill == clbytes) {
670 *a_text_fill = 0;
671 }
672 }
673 }
674
675 /*###665 [cc] `aout' undeclared (first use this function)%%%*/
676 if (aout != NULL) {
677 *aout = mid;
678 }
679
680 return(0);
681 #endif NOAOUT
682 }
683
684 /*###673 [cc] syntax error before `int'%%%*/
685 int
686 GetFileInfo(fd, load, xfr, aout,
687 a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
688 int fd, *aout;
689 u_long *load, *xfr, *a_text, *a_text_fill;
690 u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
691 {
692 int err;
693
694 err = CheckAOutFile(fd);
695
696 if (err == 0) {
697 err = GetAOutFileInfo(fd, load, xfr,
698 a_text, a_text_fill,
699 a_data, a_data_fill,
700 a_bss, a_bss_fill,
701 aout);
702 if (err != 0) {
703 return(-1);
704 }
705 } else {
706 err = CheckMopFile(fd);
707
708 if (err == 0) {
709 err = GetMopFileInfo(fd, load, xfr);
710 if (err != 0) {
711 return(-1);
712 }
713 *aout = -1;
714 } else {
715 return(-1);
716 }
717 }
718
719 return(0);
720 }
721
722 ssize_t
723 /*###711 [cc] syntax error before `mopFileRead'%%%*/
724 mopFileRead(dlslot, buf)
725 struct dllist *dlslot;
726 u_char *buf;
727 {
728 ssize_t len, outlen;
729 int bsz;
730 long pos, notdone, total;
731
732 /*###719 [cc] `dlslot' undeclared (first use this function)%%%*/
733 if (dlslot->aout == -1) {
734 /*###720 [cc] `buf' undeclared (first use this function)%%%*/
735 len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
736 } else {
737 bsz = dlslot->dl_bsz;
738 pos = dlslot->a_lseek;
739 len = 0;
740
741 total = dlslot->a_text;
742
743 if (pos < total) {
744 notdone = total - pos;
745 if (notdone <= bsz) {
746 /*###731 [cc] subscripted value is neither array nor pointer%%%*/
747 outlen = read(dlslot->ldfd,&buf[len],notdone);
748 } else {
749 /*###733 [cc] subscripted value is neither array nor pointer%%%*/
750 outlen = read(dlslot->ldfd,&buf[len],bsz);
751 }
752 len = len + outlen;
753 pos = pos + outlen;
754 bsz = bsz - outlen;
755 }
756
757 total = total + dlslot->a_text_fill;
758
759 if ((bsz > 0) && (pos < total)) {
760 notdone = total - pos;
761 if (notdone <= bsz) {
762 outlen = notdone;
763 } else {
764 outlen = bsz;
765 }
766 /*###749 [cc] subscripted value is neither array nor pointer%%%*/
767 bzero(&buf[len],outlen);
768 len = len + outlen;
769 pos = pos + outlen;
770 bsz = bsz - outlen;
771 }
772
773 total = total + dlslot->a_data;
774
775 if ((bsz > 0) && (pos < total)) {
776 notdone = total - pos;
777 if (notdone <= bsz) {
778 /*###760 [cc] subscripted value is neither array nor pointer%%%*/
779 outlen = read(dlslot->ldfd,&buf[len],notdone);
780 } else {
781 /*###762 [cc] subscripted value is neither array nor pointer%%%*/
782 outlen = read(dlslot->ldfd,&buf[len],bsz);
783 }
784 len = len + outlen;
785 pos = pos + outlen;
786 bsz = bsz - outlen;
787 }
788
789 total = total + dlslot->a_data_fill;
790
791 if ((bsz > 0) && (pos < total)) {
792 notdone = total - pos;
793 if (notdone <= bsz) {
794 outlen = notdone;
795 } else {
796 outlen = bsz;
797 }
798 /*###778 [cc] subscripted value is neither array nor pointer%%%*/
799 bzero(&buf[len],outlen);
800 len = len + outlen;
801 pos = pos + outlen;
802 bsz = bsz - outlen;
803 }
804
805 total = total + dlslot->a_bss;
806
807 if ((bsz > 0) && (pos < total)) {
808 notdone = total - pos;
809 if (notdone <= bsz) {
810 outlen = notdone;
811 } else {
812 outlen = bsz;
813 }
814 /*###793 [cc] subscripted value is neither array nor pointer%%%*/
815 bzero(&buf[len],outlen);
816 len = len + outlen;
817 pos = pos + outlen;
818 bsz = bsz - outlen;
819 }
820
821 total = total + dlslot->a_bss_fill;
822
823 if ((bsz > 0) && (pos < total)) {
824 notdone = total - pos;
825 if (notdone <= bsz) {
826 outlen = notdone;
827 } else {
828 outlen = bsz;
829 }
830 /*###808 [cc] subscripted value is neither array nor pointer%%%*/
831 bzero(&buf[len],outlen);
832 len = len + outlen;
833 pos = pos + outlen;
834 bsz = bsz - outlen;
835 }
836
837 dlslot->a_lseek = pos;
838
839 }
840
841 return(len);
842 }
843 /*###820 [cc] syntax error at end of input%%%*/
844