1: /*
   2:  * Convert old to new archive format
   3: */
   4: 
   5: #include <signal.h>
   6: #include <ar.h>
   7: 
   8: #define omag    0177555
   9: 
  10: struct  ar_hdr nh;
  11: struct
  12: {
  13:     char    oname[8];
  14:     long    odate;
  15:     char    ouid;
  16:     char    omode;
  17:     unsigned siz;
  18: } oh;
  19: 
  20: char    *tmp;
  21: char    *mktemp();
  22: int f;
  23: int tf;
  24: union {
  25:     char    buf[512];
  26:     int magic;
  27: } b;
  28: 
  29: main(argc, argv)
  30: char *argv[];
  31: {
  32:     register i;
  33: 
  34:     tmp = mktemp("/tmp/arcXXXXX");
  35:     for(i=1; i<4; i++)
  36:         signal(i, SIG_IGN);
  37:     for(i=1; i<argc; i++)
  38:         conv(argv[i]);
  39:     unlink(tmp);
  40: }
  41: 
  42: conv(fil)
  43: char *fil;
  44: {
  45:     register unsigned i, n;
  46: 
  47:     f = open(fil, 2);
  48:     if(f < 0) {
  49:         printf("arcv: cannot open %s\n", fil);
  50:         return;
  51:     }
  52:     close(creat(tmp, 0600));
  53:     tf = open(tmp, 2);
  54:     if(tf < 0) {
  55:         printf("arcv: cannot open temp\n");
  56:         close(f);
  57:         return;
  58:     }
  59:     b.magic = 0;
  60:     read(f, (char *)&b.magic, sizeof(b.magic));
  61:     if(b.magic != omag) {
  62:         printf("arcv: %s not archive format\n", fil);
  63:         close(tf);
  64:         close(f);
  65:         return;
  66:     }
  67:     b.magic = ARMAG;
  68:     write(tf, (char *)&b.magic, sizeof(b.magic));
  69: loop:
  70:     i = read(f, (char *)&oh, sizeof(oh));
  71:     if(i != sizeof(oh))
  72:         goto out;
  73:     for(i=0; i<8; i++)
  74:         nh.ar_name[i] = oh.oname[i];
  75:     nh.ar_size = oh.siz;
  76:     nh.ar_uid = oh.ouid;
  77:     nh.ar_gid = 1;
  78:     nh.ar_mode = 0666;
  79:     nh.ar_date = oh.odate;
  80:     n = (oh.siz+1) & ~01;
  81:     write(tf, (char *)&nh, sizeof(nh));
  82:     while(n > 0) {
  83:         i = 512;
  84:         if(n < i)
  85:             i = n;
  86:         read(f, b.buf, i);
  87:         write(tf, b.buf, i);
  88:         n -= i;
  89:     }
  90:     goto loop;
  91: out:
  92:     lseek(f, 0L, 0);
  93:     lseek(tf, 0L, 0);
  94:     while((i=read(tf, b.buf, 512)) > 0)
  95:         write(f, b.buf, i);
  96:     close(f);
  97:     close(tf);
  98: }

Defined functions

conv defined in line 42; used 1 times
  • in line 38
main defined in line 29; never used

Defined variables

f defined in line 22; used 10 times
nh defined in line 10; used 8 times
tf defined in line 23; used 9 times
tmp defined in line 20; used 4 times

Defined macros

omag defined in line 8; used 1 times
  • in line 61
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 763
Valid CSS Valid XHTML 1.0 Strict