|
|
1.1 ! root 1: static char sccsid[] = "@(#)arcv.c 4.1 10/1/80"; ! 2: /* ! 3: * arcv - convert old to new archive format ! 4: */ ! 5: ! 6: #include <signal.h> ! 7: #include <ar.h> ! 8: #define OARMAG 0177545 ! 9: struct oar_hdr { ! 10: char oar_name[14]; ! 11: long oar_date; ! 12: char oar_uid; ! 13: char oar_gid; ! 14: int oar_mode; ! 15: long oar_size; ! 16: }; ! 17: ! 18: struct ar_hdr nh; ! 19: struct oar_hdr oh; ! 20: char *tmp; ! 21: char *mktemp(); ! 22: int f; ! 23: char buf[512]; ! 24: int tf; ! 25: main(argc, argv) ! 26: char *argv[]; ! 27: { ! 28: register i; ! 29: ! 30: if (argc>1 && strcmp(argv[1], "-t")==0) { ! 31: tmp = mktemp("/usr/tmp/arcXXXXXX"); ! 32: argc--; ! 33: argv++; ! 34: } else ! 35: tmp = mktemp("/tmp/arcXXXXXX"); ! 36: for(i=1; i<4; i++) ! 37: signal(i, SIG_IGN); ! 38: for(i=1; i<argc; i++) { ! 39: if (argc>1) ! 40: printf("%s:\n", argv[i]); ! 41: conv(argv[i]); ! 42: } ! 43: unlink(tmp); ! 44: return(0); ! 45: } ! 46: ! 47: conv(fil) ! 48: char *fil; ! 49: { ! 50: int oldmagic; ! 51: long n; ! 52: unsigned i; ! 53: ! 54: f = open(fil, 2); ! 55: if(f < 0) { ! 56: printf("arcv: cannot open %s\n", fil); ! 57: return; ! 58: } ! 59: close(creat(tmp, 0600)); ! 60: tf = open(tmp, 2); ! 61: if(tf < 0) { ! 62: printf("arcv: cannot open temp\n"); ! 63: close(f); ! 64: return; ! 65: } ! 66: oldmagic = 0; ! 67: read(f, (char *)&oldmagic, sizeof(oldmagic)); ! 68: if(oldmagic != 0177545) { ! 69: printf("arcv: %s not old archive format\n", fil); ! 70: close(tf); ! 71: close(f); ! 72: return; ! 73: } ! 74: chkwrite(tf, ARMAG, SARMAG); ! 75: loop: ! 76: i = read(f, (char *)&oh, sizeof(oh)); ! 77: if(i != sizeof(oh)) ! 78: goto out; ! 79: ! 80: sprintf(buf, "%-16.14s%-12ld%-6u%-6u%-8o%-10ld%-2s", ! 81: oh.oar_name, ! 82: oh.oar_date, ! 83: oh.oar_uid, ! 84: oh.oar_gid, ! 85: (unsigned short)oh.oar_mode, ! 86: oh.oar_size, ! 87: ARFMAG); ! 88: strncpy((char *)&nh, buf, sizeof(nh)); ! 89: n = oh.oar_size; ! 90: chkwrite(tf, (char *)&nh, sizeof(nh)); ! 91: while(n > 0) { ! 92: i = 512; ! 93: if (n<i) ! 94: i = n; ! 95: read(f, buf, i&01? i+1:i); ! 96: if (i&01) { ! 97: buf[i] = '\n'; ! 98: i++; ! 99: } ! 100: chkwrite(tf, buf, i); ! 101: n -= i; ! 102: } ! 103: goto loop; ! 104: out: ! 105: lseek(f, 0L, 0); ! 106: lseek(tf, 0L, 0); ! 107: while((i=read(tf, buf, 512)) > 0) ! 108: chkwrite(f, buf, i); ! 109: close(f); ! 110: close(tf); ! 111: } ! 112: ! 113: chkwrite(f, b, n) ! 114: char *b; ! 115: { ! 116: if (write(f, b, n) != n) { ! 117: printf("arcv: write error\n"); ! 118: unlink(tmp); ! 119: exit(1); ! 120: } ! 121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.