=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ranlib/Attic/build.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/ranlib/Attic/build.c 1997/11/07 03:42:47 1.5 --- src/usr.bin/ranlib/Attic/build.c 1999/05/10 16:14:07 1.6 *************** *** 1,4 **** ! /* $OpenBSD: build.c,v 1.5 1997/11/07 03:42:47 deraadt Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. --- 1,4 ---- ! /* $OpenBSD: build.c,v 1.6 1999/05/10 16:14:07 espie Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. *************** *** 38,44 **** #ifndef lint /*static char sccsid[] = "from: @(#)build.c 5.3 (Berkeley) 3/12/91";*/ ! static char rcsid[] = "$OpenBSD: build.c,v 1.5 1997/11/07 03:42:47 deraadt Exp $"; #endif /* not lint */ #include --- 38,44 ---- #ifndef lint /*static char sccsid[] = "from: @(#)build.c 5.3 (Berkeley) 3/12/91";*/ ! static char rcsid[] = "$OpenBSD: build.c,v 1.6 1999/05/10 16:14:07 espie Exp $"; #endif /* not lint */ #include *************** *** 54,60 **** --- 54,62 ---- #include #include #include + #include "byte.c" + extern CHDR chdr; /* converted header */ extern char *archive; /* archive name */ extern char *tname; /* temporary file "name" */ *************** *** 71,85 **** static long symcnt; /* symbol count */ static long tsymlen; /* total string length */ ! static void rexec(), symobj(); extern void *emalloc(); build() { CF cf; int afd, tfd; off_t size; afd = open_archive(O_RDWR); fp = fdopen(afd, "r+"); tfd = tmp(); --- 73,91 ---- static long symcnt; /* symbol count */ static long tsymlen; /* total string length */ ! static int rexec(); ! static void symobj(); extern void *emalloc(); build() { CF cf; int afd, tfd; + int check_mid; + int current_mid; off_t size; + check_mid = 0; afd = open_archive(O_RDWR); fp = fdopen(afd, "r+"); tfd = tmp(); *************** *** 90,106 **** symcnt = tsymlen = 0; pnext = &rhead; while(get_arobj(afd)) { if (!strcmp(chdr.name, RANLIBMAG)) { skip_arobj(afd); continue; } ! rexec(afd, tfd); put_arobj(&cf, (struct stat *)NULL); } *pnext = NULL; ! /* Create the symbol table. */ ! symobj(); /* Copy the saved objects into the archive. */ size = lseek(tfd, (off_t)0, SEEK_CUR); --- 96,119 ---- symcnt = tsymlen = 0; pnext = &rhead; while(get_arobj(afd)) { + int new_mid; + if (!strcmp(chdr.name, RANLIBMAG)) { skip_arobj(afd); continue; } ! new_mid = rexec(afd, tfd); ! if (check_mid && new_mid != current_mid) ! errx(1, "Mixed object format archive: %d / %d", ! new_mid, current_mid); ! current_mid = new_mid; ! check_mid = 1; put_arobj(&cf, (struct stat *)NULL); } *pnext = NULL; ! /* Create the symbol table. Endianess the same as last mid seen */ ! symobj(current_mid); /* Copy the saved objects into the archive. */ size = lseek(tfd, (off_t)0, SEEK_CUR); *************** *** 119,127 **** /* * rexec * Read the exec structure; ignore any files that don't look ! * exactly right. */ ! static void rexec(rfd, wfd) register int rfd; int wfd; --- 132,140 ---- /* * rexec * Read the exec structure; ignore any files that don't look ! * exactly right. Return MID. */ ! static int rexec(rfd, wfd) register int rfd; int wfd; *************** *** 145,152 **** goto badread; /* Check magic number and symbol count. */ ! if (N_BADMAG(ebuf) || ebuf.a_syms == 0) goto bad1; /* Seek to string table. */ if (lseek(rfd, N_STROFF(ebuf) + r_off, SEEK_SET) == (off_t)-1) --- 158,166 ---- goto badread; /* Check magic number and symbol count. */ ! if (BAD_OBJECT(ebuf) || ebuf.a_syms == 0) goto bad1; + fix_header_order(&ebuf); /* Seek to string table. */ if (lseek(rfd, N_STROFF(ebuf) + r_off, SEEK_SET) == (off_t)-1) *************** *** 157,162 **** --- 171,177 ---- if (nr != sizeof(strsize)) goto badread; + strsize = fix_long_order(strsize, N_GETMID(ebuf)); /* Read in the string table. */ strsize -= sizeof(strsize); strtab = (char *)emalloc(strsize); *************** *** 179,184 **** --- 194,200 ---- badfmt(); error(archive); } + fix_nlist_order(&nl, N_GETMID(ebuf)); /* Ignore if no name or local. */ if (!nl.n_un.n_strx || !(nl.n_type & N_EXT)) *************** *** 211,225 **** bad2: free(strtab); bad1: (void)lseek(rfd, (off_t)r_off, SEEK_SET); } /* * symobj -- * Write the symbol table into the archive, computing offsets as ! * writing. */ static void ! symobj() { register RLIB *rp, *rnext; struct ranlib rn; --- 227,243 ---- bad2: free(strtab); bad1: (void)lseek(rfd, (off_t)r_off, SEEK_SET); + return N_GETMID(ebuf); } /* * symobj -- * Write the symbol table into the archive, computing offsets as ! * writing. Use the right format depending on mid. */ static void ! symobj(mid) ! int mid; { register RLIB *rp, *rnext; struct ranlib rn; *************** *** 260,266 **** error(tname); /* First long is the size of the ranlib structure section. */ ! size = symcnt * sizeof(struct ranlib); if (!fwrite((char *)&size, sizeof(size), 1, fp)) error(tname); --- 278,284 ---- error(tname); /* First long is the size of the ranlib structure section. */ ! size = fix_long_order(symcnt * sizeof(struct ranlib), mid); if (!fwrite((char *)&size, sizeof(size), 1, fp)) error(tname); *************** *** 276,287 **** rn.ran_un.ran_strx = stroff; stroff += rp->symlen; rn.ran_off = size + rp->pos; if (!fwrite((char *)&rn, sizeof(struct ranlib), 1, fp)) error(archive); } /* Second long is the size of the string table. */ ! if (!fwrite((char *)&tsymlen, sizeof(tsymlen), 1, fp)) error(tname); /* Write out the string table. */ --- 294,308 ---- rn.ran_un.ran_strx = stroff; stroff += rp->symlen; rn.ran_off = size + rp->pos; + fix_ranlib_order(&rn, mid); if (!fwrite((char *)&rn, sizeof(struct ranlib), 1, fp)) error(archive); } /* Second long is the size of the string table. */ ! ! size = fix_long_order(tsymlen, mid); ! if (!fwrite((char *)&size, sizeof(size), 1, fp)) error(tname); /* Write out the string table. */