Bell 32V development
[unix-history] / usr / src / standalone / vrmhead.c
CommitLineData
298992c3
TL
1# define VAX 1
2struct {short hiword; short loword;}; /* stupid fp-11 */
3fixl(p) register long *p;{
4 register short t;
5 t=p->hiword; p->hiword=p->loword; p->loword=t;
6}
7
8main(argc,args)
9int argc ;
10char **args ;
11{
12int ifd , ofd , nbyt , ttt;
13register char *infile , *oufile , *ap ;
14char * fbuf, zero;
15struct {
16 long magic;
17 long tlen,dlen;
18 long blen,slen,eadr,trl,drl;
19} head;
20
21char buf[512] ;
22
23zero = '\0';
24if (argc != 3) {
25 usage :
26 printf("usage : rmhead input output\n") ;
27 exit(1) ;
28 }
29
30infile = args[1] ;
31oufile = args[2] ;
32
33if ((ifd = open(infile,0)) < 0) {
34 ap = infile ;
35 oerr :
36 printf("%s : cannot open\n",ap) ;
37 exit(1) ;
38 }
39
40if ((ofd = creat(oufile,0777)) < 0) {
41 ap = oufile ;
42 goto oerr ;
43 }
44
45read(ifd,&head,sizeof head);
46#ifndef VAX
47fixl(&head.tlen); fixl(&head.dlen);
48#endif
49if (seek(ifd,sizeof head,0) < 0) {
50 printf("input seek error\n") ;
51 unlnk :
52 unlink(oufile) ;
53 exit(1) ;
54 }
55
56fbuf=sbrk(4096);
57while (head.tlen>0) {
58 if (head.tlen>4096) nbyt=4096; else nbyt=head.tlen;
59 read(ifd,fbuf,nbyt);
60 write(ofd,fbuf,nbyt);
61 head.tlen -= nbyt;
62}
63while (nbyt&0777) {write(ofd,&zero,1); ++nbyt;}
64while (head.dlen>0) {
65 if (head.dlen>4096) nbyt=4096; else nbyt=head.dlen;
66 read(ifd,fbuf,nbyt);
67 write(ofd,fbuf,nbyt);
68 head.dlen -= nbyt;
69}
70return(0);
71}