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