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: }

Defined functions

chkwrite defined in line 113; used 4 times
conv defined in line 47; used 1 times
  • in line 41
main defined in line 25; never used

Defined variables

buf defined in line 23; used 7 times
f defined in line 22; used 12 times
nh defined in line 18; used 4 times
oh defined in line 19; used 10 times
sccsid defined in line 1; never used
tf defined in line 24; used 9 times
tmp defined in line 20; used 6 times

Defined struct's

oar_hdr defined in line 9; used 2 times
  • in line 19(2)

Defined macros

OARMAG defined in line 8; never used
Last modified: 1990-11-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3357
Valid CSS Valid XHTML 1.0 Strict