|
|
1.1 ! root 1: #include "strip.h" ! 2: #include "hash.h" ! 3: ! 4: symwrite(a) ! 5: register Adotout *a; ! 6: { ! 7: int utmp; ! 8: struct stx { ! 9: char *lo, *hi; ! 10: int base; ! 11: } *stxtab, *stxend; ! 12: char *rindex(), *mktemp(), *strcpy(); ! 13: ! 14: register struct nlist *sym; ! 15: register struct stx *stabx; register char *cp; ! 16: ! 17: struct st *stab; int strcount = 4; ! 18: int tofd, error = 0; ! 19: ! 20: mktemp(strcpy(tmpnam, "/tmp/stripXXXXXX")); ! 21: tofd = creat(tmpnam, 0666); ! 22: if (tofd < 0) ! 23: return failure("cannot creat ", tmpnam); ! 24: ! 25: lseek(a->fd, 0, 0); ! 26: error = fcopy(tofd, a->fd, N_SYMOFF(a->hd)); ! 27: ! 28: if (a->symtab) { ! 29: stabx = stxtab = Malloc(struct stx, stcount); ! 30: stxend = stxtab + stcount; ! 31: for (stab = sroot; stab; stab = stab->next, stabx++) { ! 32: stabx->lo = stab->strtab; ! 33: stabx->hi = stabx->lo + stab->nused; ! 34: stabx->base = (long)(stabx->lo) - strcount; ! 35: strcount += stab->nused; ! 36: } ! 37: for (sym=a->symtab; sym<a->symend; sym++) ! 38: if (cp = sym->n_un.n_name) { ! 39: stabx = stxtab; ! 40: while (cp < stabx->lo || cp >= stabx->hi) ++stabx; ! 41: sym->n_un.n_name -= stabx->base; ! 42: } ! 43: free(stxtab); ! 44: a->hd.a_syms = (char *)a->symend - (char *)a->symtab; ! 45: } else ! 46: a->hd.a_syms = 0; ! 47: ! 48: lseek(tofd, 0, 0); ! 49: error |= Write(tofd, (char *)&a->hd, sizeof(struct exec)); ! 50: ! 51: if (a->symtab) { ! 52: lseek(tofd, N_SYMOFF(a->hd), 0); ! 53: error |= Write(tofd, a->symtab, a->hd.a_syms); ! 54: error |= Write(tofd, &strcount, 4); ! 55: for (stab = sroot; stab; stab = stab->next) ! 56: error |= Write(tofd, stab->strtab, stab->nused); ! 57: } ! 58: error |= close(tofd); ! 59: close(a->fd); ! 60: if (error) ! 61: return failure("cannot write ", tmpnam); ! 62: if ((a->fd = open(tmpnam, 0)) < 0) ! 63: return failure("cannot reopen ", tmpnam); ! 64: fstat(a->fd, &a->filstat); ! 65: utmp = umask(0); ! 66: tofd = creat(a->name, a->filstat.st_mode); ! 67: (void)umask(utmp); ! 68: if (tofd < 0) ! 69: return failure("cannot creat ", a->name); ! 70: ++copyrace; ! 71: fcopy(tofd, a->fd, a->filstat.st_size); ! 72: close(tofd); ! 73: close(a->fd); ! 74: --copyrace; ! 75: if (unlink(tmpnam) < 0) ! 76: return failure("cannot unlink ", tmpnam); ! 77: return 0; ! 78: } ! 79: ! 80: failure(m1, m2) ! 81: char *m1, *m2; ! 82: { ! 83: if (m1) ! 84: fprintf(stderr,"%s: %s%s\n", prognam, m1, m2); ! 85: if (!copyrace && tmpnam[0]) ! 86: unlink(tmpnam); ! 87: return 1; ! 88: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.