imgtec-ci20: genimage config/ u-boot env
[openadk.git] / package / mopd / src / common / file.c
blob8d2ffcd945fde7f9fa7e28b428a846c0be84353a
1 /* $NetBSD: file.c,v 1.5 1998/02/07 00:03:22 cgd Exp $ */
3 /*
4 * Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Mats O Jansson.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 static char rcsid[]="$NetBSD: file.c,v 1.5 1998/02/07 00:03:22 cgd Exp $";
35 #endif
37 #include "os.h"
38 #include "common.h"
39 #include "file.h"
40 #include "mopdef.h"
42 #ifndef NOAOUT
43 #if defined(__NetBSD__) || defined(__OpenBSD__)
44 #include <sys/exec_aout.h>
45 #endif
46 #if defined(__bsdi__)
47 #define NOAOUT
48 #endif
49 #if defined(__FreeBSD__)
50 #include <sys/imgact_aout.h>
51 #endif
52 #if !defined(MID_VAX)
53 #define MID_VAX 140
54 #endif
55 #if defined(__linux__)
56 #define NOAOUT
57 #include <a.out.h>
58 #define MID_I386 100
59 #define MID_SPARC 3
60 #endif
61 #endif
63 int getCLBYTES __P((int));
64 int getMID __P((int, int));
66 void
67 mopFilePutLX(buf, index, value, cnt)
68 u_char *buf;
69 int index, cnt;
70 u_int32_t value;
72 int i;
73 for (i = 0; i < cnt; i++) {
74 buf[index+i] = value % 256;
75 value = value / 256;
79 void
80 mopFilePutBX(buf, index, value, cnt)
81 u_char *buf;
82 int index, cnt;
83 u_int32_t value;
85 int i;
86 for (i = 0; i < cnt; i++) {
87 buf[index+cnt-1-i] = value % 256;
88 value = value / 256;
92 u_int32_t
93 mopFileGetLX(buf, index, cnt)
94 u_char *buf;
95 int index, cnt;
97 u_int32_t ret = 0;
98 int i;
100 for (i = 0; i < cnt; i++) {
101 ret = ret*256 + buf[index+cnt-1-i];
104 return(ret);
107 u_int32_t
108 mopFileGetBX(buf, index, cnt)
109 u_char *buf;
110 int index, cnt;
112 u_int32_t ret = 0;
113 int i;
115 for (i = 0; i < cnt; i++) {
116 ret = ret*256 + buf[index+i];
119 return(ret);
122 void
123 mopFileSwapX(buf, index, cnt)
124 u_char *buf;
125 int index, cnt;
127 int i;
128 u_char c;
130 for (i = 0; i < (cnt / 2); i++) {
131 c = buf[index+i];
132 buf[index+i] = buf[index+cnt-1-i];
133 buf[index+cnt-1-i] = c;
139 CheckMopFile(fd)
140 int fd;
142 u_char header[512];
143 short image_type;
145 if (read(fd, header, 512) != 512)
146 return(-1);
148 (void)lseek(fd, (off_t) 0, SEEK_SET);
150 image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
151 header[IHD_W_ALIAS]);
153 switch(image_type) {
154 case IHD_C_NATIVE: /* Native mode image (VAX) */
155 case IHD_C_RSX: /* RSX image produced by TKB */
156 case IHD_C_BPA: /* BASIC plus analog */
157 case IHD_C_ALIAS: /* Alias */
158 case IHD_C_CLI: /* Image is CLI */
159 case IHD_C_PMAX: /* PMAX system image */
160 case IHD_C_ALPHA: /* ALPHA system image */
161 break;
162 default:
163 return(-1);
166 return(0);
170 GetMopFileInfo(fd, load, xfr)
171 int fd;
172 u_int32_t *load, *xfr;
174 u_char header[512];
175 short image_type;
176 u_int32_t load_addr, xfr_addr, isd, iha, hbcnt, isize;
178 if (read(fd, header, 512) != 512)
179 return(-1);
181 image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
182 header[IHD_W_ALIAS]);
184 switch(image_type) {
185 case IHD_C_NATIVE: /* Native mode image (VAX) */
186 isd = (header[IHD_W_SIZE+1]*256 +
187 header[IHD_W_SIZE]);
188 iha = (header[IHD_W_ACTIVOFF+1]*256 +
189 header[IHD_W_ACTIVOFF]);
190 hbcnt = (header[IHD_B_HDRBLKCNT]);
191 isize = (header[isd+ISD_W_PAGCNT+1]*256 +
192 header[isd+ISD_W_PAGCNT]) * 512;
193 load_addr = ((header[isd+ISD_V_VPN+1]*256 +
194 header[isd+ISD_V_VPN]) & ISD_M_VPN)
195 * 512;
196 xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
197 header[iha+IHA_L_TFRADR1+2]*0x10000 +
198 header[iha+IHA_L_TFRADR1+1]*0x100 +
199 header[iha+IHA_L_TFRADR1]) & 0x7fffffff;
200 printf("Native Image (VAX)\n");
201 printf("Header Block Count: %d\n",hbcnt);
202 printf("Image Size: %08x\n",isize);
203 printf("Load Address: %08x\n",load_addr);
204 printf("Transfer Address: %08x\n",xfr_addr);
205 break;
206 case IHD_C_RSX: /* RSX image produced by TKB */
207 hbcnt = header[L_BBLK+1]*256 + header[L_BBLK];
208 isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64;
209 load_addr = header[L_BSA+1]*256 + header[L_BSA];
210 xfr_addr = header[L_BXFR+1]*256 + header[L_BXFR];
211 printf("RSX Image\n");
212 printf("Header Block Count: %d\n",hbcnt);
213 printf("Image Size: %08x\n",isize);
214 printf("Load Address: %08x\n",load_addr);
215 printf("Transfer Address: %08x\n",xfr_addr);
216 break;
217 case IHD_C_BPA: /* BASIC plus analog */
218 printf("BASIC-Plus Image, not supported\n");
219 return(-1);
220 break;
221 case IHD_C_ALIAS: /* Alias */
222 printf("Alias, not supported\n");
223 return(-1);
224 break;
225 case IHD_C_CLI: /* Image is CLI */
226 printf("CLI, not supported\n");
227 return(-1);
228 break;
229 case IHD_C_PMAX: /* PMAX system image */
230 isd = (header[IHD_W_SIZE+1]*256 +
231 header[IHD_W_SIZE]);
232 iha = (header[IHD_W_ACTIVOFF+1]*256 +
233 header[IHD_W_ACTIVOFF]);
234 hbcnt = (header[IHD_B_HDRBLKCNT]);
235 isize = (header[isd+ISD_W_PAGCNT+1]*256 +
236 header[isd+ISD_W_PAGCNT]) * 512;
237 load_addr = (header[isd+ISD_V_VPN+1]*256 +
238 header[isd+ISD_V_VPN]) * 512;
239 xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
240 header[iha+IHA_L_TFRADR1+2]*0x10000 +
241 header[iha+IHA_L_TFRADR1+1]*0x100 +
242 header[iha+IHA_L_TFRADR1]);
243 printf("PMAX Image \n");
244 printf("Header Block Count: %d\n",hbcnt);
245 printf("Image Size: %08x\n",isize);
246 printf("Load Address: %08x\n",load_addr);
247 printf("Transfer Address: %08x\n",xfr_addr);
248 break;
249 case IHD_C_ALPHA: /* ALPHA system image */
250 isd = (header[EIHD_L_ISDOFF+3]*0x1000000 +
251 header[EIHD_L_ISDOFF+2]*0x10000 +
252 header[EIHD_L_ISDOFF+1]*0x100 +
253 header[EIHD_L_ISDOFF]);
254 hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 +
255 header[EIHD_L_HDRBLKCNT+2]*0x10000 +
256 header[EIHD_L_HDRBLKCNT+1]*0x100 +
257 header[EIHD_L_HDRBLKCNT]);
258 isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 +
259 header[isd+EISD_L_SECSIZE+2]*0x10000 +
260 header[isd+EISD_L_SECSIZE+1]*0x100 +
261 header[isd+EISD_L_SECSIZE]);
262 load_addr = 0;
263 xfr_addr = 0;
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 break;
270 default:
271 printf("Unknown Image (%d)\n",image_type);
272 return(-1);
275 if (load != NULL) {
276 *load = load_addr;
279 if (xfr != NULL) {
280 *xfr = xfr_addr;
283 return(0);
286 #ifndef NOAOUT
288 getMID(old_mid,new_mid)
289 int old_mid, new_mid;
291 int mid;
293 mid = old_mid;
295 switch (new_mid) {
296 case MID_I386:
297 mid = MID_I386;
298 break;
299 #ifdef MID_M68K
300 case MID_M68K:
301 mid = MID_M68K;
302 break;
303 #endif
304 #ifdef MID_M68K4K
305 case MID_M68K4K:
306 mid = MID_M68K4K;
307 break;
308 #endif
309 #ifdef MID_NS32532
310 case MID_NS32532:
311 mid = MID_NS32532;
312 break;
313 #endif
314 case MID_SPARC:
315 mid = MID_SPARC;
316 break;
317 #ifdef MID_PMAX
318 case MID_PMAX:
319 mid = MID_PMAX;
320 break;
321 #endif
322 #ifdef MID_VAX
323 case MID_VAX:
324 mid = MID_VAX;
325 break;
326 #endif
327 #ifdef MID_ALPHA
328 case MID_ALPHA:
329 mid = MID_ALPHA;
330 break;
331 #endif
332 #ifdef MID_MIPS
333 case MID_MIPS:
334 mid = MID_MIPS;
335 break;
336 #endif
337 #ifdef MID_ARM6
338 case MID_ARM6:
339 mid = MID_ARM6;
340 break;
341 #endif
342 default:
343 break;
346 return(mid);
350 getCLBYTES(mid)
351 int mid;
353 int clbytes;
355 switch (mid) {
356 #ifdef MID_VAX
357 case MID_VAX:
358 clbytes = 1024;
359 break;
360 #endif
361 #ifdef MID_I386
362 case MID_I386:
363 #endif
364 #ifdef MID_M68K4K
365 case MID_M68K4K:
366 #endif
367 #ifdef MID_NS32532
368 case MID_NS32532:
369 #endif
370 #ifdef MID_PMAX
371 case MID_PMAX:
372 #endif
373 #ifdef MID_MIPS
374 case MID_MIPS:
375 #endif
376 #ifdef MID_ARM6
377 case MID_ARM6:
378 #endif
379 #if defined(MID_I386) || defined(MID_M68K4K) || defined(MID_NS32532) || \
380 defined(MID_PMAX) || defined(MID_MIPS) || defined(MID_ARM6)
381 clbytes = 4096;
382 break;
383 #endif
384 #ifdef MID_M68K
385 case MID_M68K:
386 #endif
387 #ifdef MID_ALPHA
388 case MID_ALPHA:
389 #endif
390 #ifdef MID_SPARC
391 case MID_SPARC:
392 #endif
393 #if defined(MID_M68K) || defined(MID_ALPHA) || defined(MID_SPARC)
394 clbytes = 8192;
395 break;
396 #endif
397 default:
398 clbytes = 0;
401 return(clbytes);
403 #endif
406 CheckAOutFile(fd)
407 int fd;
409 #ifdef NOAOUT
410 return(-1);
411 #else
412 struct exec ex, ex_swap;
413 int mid = -1;
415 if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
416 return(-1);
418 (void)lseek(fd, (off_t) 0, SEEK_SET);
420 if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
421 return(-1);
423 (void)lseek(fd, (off_t) 0, SEEK_SET);
425 mid = getMID(mid, N_GETMID (ex));
427 if (mid == -1) {
428 mid = getMID(mid, N_GETMID (ex_swap));
431 if (mid != -1) {
432 return(0);
433 } else {
434 return(-1);
436 #endif NOAOUT
440 GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
441 a_data, a_data_fill, a_bss, a_bss_fill, aout)
442 int fd;
443 u_int32_t *load, *xfr, *a_text, *a_text_fill;
444 u_int32_t *a_data, *a_data_fill, *a_bss, *a_bss_fill;
445 int *aout;
447 #ifdef NOAOUT
448 return(-1);
449 #else
450 struct exec ex, ex_swap;
451 u_int32_t mid = -1;
452 u_int32_t magic, clbytes, clofset;
454 if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
455 return(-1);
457 (void)lseek(fd, (off_t) 0, SEEK_SET);
459 if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
460 return(-1);
462 mopFileSwapX((u_char *)&ex_swap, 0, 4);
464 mid = getMID(mid, N_GETMID (ex));
466 if (mid == -1) {
467 mid = getMID(mid, N_GETMID (ex_swap));
468 if (mid != -1) {
469 mopFileSwapX((u_char *)&ex, 0, 4);
473 if (mid == -1) {
474 return(-1);
477 if (N_BADMAG (ex)) {
478 return(-1);
481 switch (mid) {
482 case MID_I386:
483 #ifdef MID_NS32532
484 case MID_NS32532:
485 #endif
486 #ifdef MID_PMAX
487 case MID_PMAX:
488 #endif
489 #ifdef MID_VAX
490 case MID_VAX:
491 #endif
492 #ifdef MID_ALPHA
493 case MID_ALPHA:
494 #endif
495 #ifdef MID_ARM6
496 case MID_ARM6:
497 #endif
498 ex.a_text = mopFileGetLX((u_char *)&ex_swap, 4, 4);
499 ex.a_data = mopFileGetLX((u_char *)&ex_swap, 8, 4);
500 ex.a_bss = mopFileGetLX((u_char *)&ex_swap, 12, 4);
501 ex.a_syms = mopFileGetLX((u_char *)&ex_swap, 16, 4);
502 ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4);
503 ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4);
504 ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4);
505 break;
506 #ifdef MID_M68K
507 case MID_M68K:
508 #endif
509 #ifdef MID_M68K4K
510 case MID_M68K4K:
511 #endif
512 case MID_SPARC:
513 #ifdef MID_MIPS
514 case MID_MIPS:
515 #endif
516 ex.a_text = mopFileGetBX((u_char *)&ex_swap, 4, 4);
517 ex.a_data = mopFileGetBX((u_char *)&ex_swap, 8, 4);
518 ex.a_bss = mopFileGetBX((u_char *)&ex_swap, 12, 4);
519 ex.a_syms = mopFileGetBX((u_char *)&ex_swap, 16, 4);
520 ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4);
521 ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4);
522 ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4);
523 break;
524 default:
525 break;
528 printf("a.out image (");
529 switch (N_GETMID (ex)) {
530 case MID_I386:
531 printf("i386");
532 break;
533 #ifdef MID_M68K
534 case MID_M68K:
535 printf("m68k");
536 break;
537 #endif
538 #ifdef MID_M68K4K
539 case MID_M68K4K:
540 printf("m68k 4k");
541 break;
542 #endif
543 #ifdef MID_NS32532
544 case MID_NS32532:
545 printf("pc532");
546 break;
547 #endif
548 case MID_SPARC:
549 printf("sparc");
550 break;
551 #ifdef MID_PMAX
552 case MID_PMAX:
553 printf("pmax");
554 break;
555 #endif
556 #ifdef MID_VAX
557 case MID_VAX:
558 printf("vax");
559 break;
560 #endif
561 #ifdef MID_ALPHA
562 case MID_ALPHA:
563 printf("alpha");
564 break;
565 #endif
566 #ifdef MID_MIPS
567 case MID_MIPS:
568 printf("mips");
569 break;
570 #endif
571 #ifdef MID_ARM6
572 case MID_ARM6:
573 printf("arm32");
574 break;
575 #endif
576 default:
577 break;
579 printf(") Magic: ");
580 switch (N_GETMAGIC (ex)) {
581 case OMAGIC:
582 printf("OMAGIC");
583 break;
584 case NMAGIC:
585 printf("NMAGIC");
586 break;
587 case ZMAGIC:
588 printf("ZMAGIC");
589 break;
590 case QMAGIC:
591 printf("QMAGIC");
592 break;
593 default:
594 printf("Unknown %ld", (long) N_GETMAGIC (ex));
596 printf("\n");
597 printf("Size of text: %08lx\n", (long)ex.a_text);
598 printf("Size of data: %08lx\n", (long)ex.a_data);
599 printf("Size of bss: %08lx\n", (long)ex.a_bss);
600 printf("Size of symbol tab: %08lx\n", (long)ex.a_syms);
601 printf("Transfer Address: %08lx\n", (long)ex.a_entry);
602 printf("Size of reloc text: %08lx\n", (long)ex.a_trsize);
603 printf("Size of reloc data: %08lx\n", (long)ex.a_drsize);
605 magic = N_GETMAGIC (ex);
606 clbytes = getCLBYTES(mid);
607 clofset = clbytes - 1;
609 if (load != NULL) {
610 *load = 0;
613 if (xfr != NULL) {
614 *xfr = ex.a_entry;
617 if (a_text != NULL) {
618 *a_text = ex.a_text;
621 if (a_text_fill != NULL) {
622 if (magic == ZMAGIC || magic == NMAGIC) {
623 *a_text_fill = clbytes - (ex.a_text & clofset);
624 if (*a_text_fill == clbytes) {
625 *a_text_fill = 0;
627 } else {
628 *a_text_fill = 0;
632 if (a_data != NULL) {
633 *a_data = ex.a_data;
636 if (a_data_fill != NULL) {
637 if (magic == ZMAGIC || magic == NMAGIC) {
638 *a_data_fill = clbytes - (ex.a_data & clofset);
639 if (*a_data_fill == clbytes) {
640 *a_data_fill = 0;
642 } else {
643 *a_data_fill = 0;
647 if (a_bss != NULL) {
648 *a_bss = ex.a_bss;
651 if (a_bss_fill != NULL) {
652 if (magic == ZMAGIC || magic == NMAGIC) {
653 *a_bss_fill = clbytes - (ex.a_bss & clofset);
654 if (*a_bss_fill == clbytes) {
655 *a_bss_fill = 0;
657 } else {
658 *a_bss_fill = clbytes -
659 ((ex.a_text+ex.a_data+ex.a_bss) & clofset);
660 if (*a_text_fill == clbytes) {
661 *a_text_fill = 0;
666 if (aout != NULL) {
667 *aout = mid;
670 return(0);
671 #endif NOAOUT
675 GetFileInfo(fd, load, xfr, aout,
676 a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
677 int fd, *aout;
678 u_int32_t *load, *xfr, *a_text, *a_text_fill;
679 u_int32_t *a_data, *a_data_fill, *a_bss, *a_bss_fill;
681 int err;
683 err = CheckAOutFile(fd);
685 if (err == 0) {
686 err = GetAOutFileInfo(fd, load, xfr,
687 a_text, a_text_fill,
688 a_data, a_data_fill,
689 a_bss, a_bss_fill,
690 aout);
691 if (err != 0) {
692 return(-1);
694 } else {
695 err = CheckMopFile(fd);
697 if (err == 0) {
698 err = GetMopFileInfo(fd, load, xfr);
699 if (err != 0) {
700 return(-1);
702 *aout = -1;
703 } else {
704 return(-1);
708 return(0);
711 ssize_t
712 mopFileRead(dlslot, buf)
713 struct dllist *dlslot;
714 u_char *buf;
716 ssize_t len, outlen;
717 int bsz;
718 int32_t pos, notdone, total;
720 if (dlslot->aout == -1) {
721 len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
722 } else {
723 bsz = dlslot->dl_bsz;
724 pos = dlslot->a_lseek;
725 len = 0;
727 total = dlslot->a_text;
729 if (pos < total) {
730 notdone = total - pos;
731 if (notdone <= bsz) {
732 outlen = read(dlslot->ldfd,&buf[len],notdone);
733 } else {
734 outlen = read(dlslot->ldfd,&buf[len],bsz);
736 len = len + outlen;
737 pos = pos + outlen;
738 bsz = bsz - outlen;
741 total = total + dlslot->a_text_fill;
743 if ((bsz > 0) && (pos < total)) {
744 notdone = total - pos;
745 if (notdone <= bsz) {
746 outlen = notdone;
747 } else {
748 outlen = bsz;
750 memset(&buf[len], 0, outlen);
751 len = len + outlen;
752 pos = pos + outlen;
753 bsz = bsz - outlen;
756 total = total + dlslot->a_data;
758 if ((bsz > 0) && (pos < total)) {
759 notdone = total - pos;
760 if (notdone <= bsz) {
761 outlen = read(dlslot->ldfd,&buf[len],notdone);
762 } else {
763 outlen = read(dlslot->ldfd,&buf[len],bsz);
765 len = len + outlen;
766 pos = pos + outlen;
767 bsz = bsz - outlen;
770 total = total + dlslot->a_data_fill;
772 if ((bsz > 0) && (pos < total)) {
773 notdone = total - pos;
774 if (notdone <= bsz) {
775 outlen = notdone;
776 } else {
777 outlen = bsz;
779 memset(&buf[len], 0, outlen);
780 len = len + outlen;
781 pos = pos + outlen;
782 bsz = bsz - outlen;
785 total = total + dlslot->a_bss;
787 if ((bsz > 0) && (pos < total)) {
788 notdone = total - pos;
789 if (notdone <= bsz) {
790 outlen = notdone;
791 } else {
792 outlen = bsz;
794 memset(&buf[len], 0, outlen);
795 len = len + outlen;
796 pos = pos + outlen;
797 bsz = bsz - outlen;
800 total = total + dlslot->a_bss_fill;
802 if ((bsz > 0) && (pos < total)) {
803 notdone = total - pos;
804 if (notdone <= bsz) {
805 outlen = notdone;
806 } else {
807 outlen = bsz;
809 memset(&buf[len], 0, outlen);
810 len = len + outlen;
811 pos = pos + outlen;
812 bsz = bsz - outlen;
815 dlslot->a_lseek = pos;
819 return(len);