static char sccsid
[] = "@(#)ranlib.c 4.3 %G%";
* ranlib - create table of contents for archive; string table version
struct ranlib tab
[TABSZ
];
char tempnm
[] = "__.SYMDEF";
fprintf(stderr
, "ranlib: cannot open %s\n", *argv
);
fread(magbuf
, 1, SARMAG
, fi
);
if (strncmp(magbuf
, ARMAG
, SARMAG
)) {
if (*(int *)magbuf
== OARMAG
)
fprintf(stderr
, "old format ");
fprintf(stderr
, "not an ");
fprintf(stderr
, "archive: %s\n", *argv
);
fread((char *)&exp
, 1, sizeof(struct exec
), fi
);
fprintf(stderr
, "ranlib: warning: %s(%s): no symbol table\n", *argv
, archdr
.ar_name
);
o
= N_STROFF(exp
) - sizeof (struct exec
);
if (ftell(fi
)+o
+sizeof(ssiz
) >= off
) {
fprintf(stderr
, "ranlib: %s(%s): old format .o file\n", *argv
, archdr
.ar_name
);
fread((char *)&ssiz
, 1, sizeof (ssiz
), fi
);
strtab
= (char *)calloc(1, ssiz
);
fprintf(stderr
, "ranlib: ran out of memory\n");
fread(strtab
+sizeof(ssiz
), ssiz
- sizeof(ssiz
), 1, fi
);
fseek(fi
, -(exp
.a_syms
+ssiz
), 1);
n
= exp
.a_syms
/ sizeof(struct nlist
);
fread((char *)&sym
, 1, sizeof(sym
), fi
);
if (sym
.n_un
.n_strx
== 0)
sym
.n_un
.n_name
= strtab
+ sym
.n_un
.n_strx
;
if ((sym
.n_type
&N_EXT
)==0)
switch (sym
.n_type
&N_TYPE
) {
fprintf(stderr
, "can't create temporary\n");
tnum
*= sizeof (struct ranlib
);
fwrite(&tnum
, 1, sizeof (tnum
), fo
);
tnum
/= sizeof (struct ranlib
);
fwrite((char *)tab
, tnum
, sizeof(struct ranlib
), fo
);
fwrite(&tssiz
, 1, sizeof (tssiz
), fo
);
fwrite(tstrtab
, tssiz
, 1, fo
);
sprintf(cmdbuf
, "ar rlb %s %s %s\n", firstname
, *argv
, tempnm
);
sprintf(cmdbuf
, "ar rl %s %s\n", *argv
, tempnm
);
fprintf(stderr
, "ranlib: ``%s'' failed\n", cmdbuf
);
r
= fread((char *)&archdr
, 1, sizeof(struct ar_hdr
), af
);
if (r
!= sizeof(struct ar_hdr
))
for (cp
=archdr
.ar_name
; cp
< & archdr
.ar_name
[sizeof(archdr
.ar_name
)]; cp
++)
arsize
= atol(archdr
.ar_size
);
off
= ftell(af
) + arsize
;
fprintf(stderr
, "ranlib: symbol table overflow\n");
tab
[tnum
].ran_un
.ran_strx
= tssiz
;
tab
[tnum
].ran_off
= oldoff
;
for (cp
= s
->n_un
.n_name
; tstrtab
[tssiz
++] = *cp
++;)
fprintf(stderr
, "ranlib: string table overflow\n");
offdelta
= sizeof(archdr
) + sizeof (tnum
) + tnum
* sizeof(struct ranlib
) +
if(strncmp(archdr
.ar_name
, tempnm
, sizeof (archdr
.ar_name
)) == 0) {
offdelta
-= sizeof(archdr
) + arsize
;
strncpy(firstname
, archdr
.ar_name
, sizeof(archdr
.ar_name
));
tab
[i
].ran_off
+= offdelta
;
fprintf(stderr
, "ranlib: can't reopen %s\n", s
);
sprintf(buf
, "%-*ld", sizeof(archdr
.ar_date
), time((long *)NULL
)+5);
lseek(fd
, (long)SARMAG
+ ((char *)archdr
.ar_date
-(char *)&archdr
), 0);
write(fd
, buf
, sizeof(archdr
.ar_date
));