1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1988 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "uucp.h" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include "pk.h" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate struct pack *Pk; 38*7c478bd9Sstevel@tonic-gate extern int gwrblk(), grdblk(), pkread(), pkwrite(); 39*7c478bd9Sstevel@tonic-gate extern void pkclose(); 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate extern int packsize, xpacksize; 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate jmp_buf Getjbuf, Gfailbuf; 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate static void (*gsig)(); 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 48*7c478bd9Sstevel@tonic-gate static void 49*7c478bd9Sstevel@tonic-gate galarm(sig) 50*7c478bd9Sstevel@tonic-gate int sig; 51*7c478bd9Sstevel@tonic-gate { 52*7c478bd9Sstevel@tonic-gate signal(SIGALRM, galarm); 53*7c478bd9Sstevel@tonic-gate longjmp(Getjbuf, 1); 54*7c478bd9Sstevel@tonic-gate } 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate void 57*7c478bd9Sstevel@tonic-gate pkfail() 58*7c478bd9Sstevel@tonic-gate { 59*7c478bd9Sstevel@tonic-gate longjmp(Gfailbuf, 1); 60*7c478bd9Sstevel@tonic-gate } 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate int 63*7c478bd9Sstevel@tonic-gate gturnon() 64*7c478bd9Sstevel@tonic-gate { 65*7c478bd9Sstevel@tonic-gate struct pack *pkopen(); 66*7c478bd9Sstevel@tonic-gate if (setjmp(Gfailbuf)) 67*7c478bd9Sstevel@tonic-gate return(FAIL); 68*7c478bd9Sstevel@tonic-gate gsig=signal(SIGALRM, galarm); 69*7c478bd9Sstevel@tonic-gate if (Debug > 4) 70*7c478bd9Sstevel@tonic-gate pkdebug = 1; 71*7c478bd9Sstevel@tonic-gate Pk = pkopen(Ifn, Ofn); 72*7c478bd9Sstevel@tonic-gate if ((int) Pk == NULL) 73*7c478bd9Sstevel@tonic-gate return(FAIL); 74*7c478bd9Sstevel@tonic-gate return(0); 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate int 78*7c478bd9Sstevel@tonic-gate gturnoff() 79*7c478bd9Sstevel@tonic-gate { 80*7c478bd9Sstevel@tonic-gate if(setjmp(Gfailbuf)) 81*7c478bd9Sstevel@tonic-gate return(FAIL); 82*7c478bd9Sstevel@tonic-gate pkclose(); 83*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, gsig); 84*7c478bd9Sstevel@tonic-gate return(0); 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 88*7c478bd9Sstevel@tonic-gate int 89*7c478bd9Sstevel@tonic-gate gwrmsg(type, str, fn) 90*7c478bd9Sstevel@tonic-gate char type, *str; 91*7c478bd9Sstevel@tonic-gate { 92*7c478bd9Sstevel@tonic-gate char bufr[BUFSIZ], *s; 93*7c478bd9Sstevel@tonic-gate int len, i; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate if(setjmp(Gfailbuf)) 96*7c478bd9Sstevel@tonic-gate return(FAIL); 97*7c478bd9Sstevel@tonic-gate bufr[0] = type; 98*7c478bd9Sstevel@tonic-gate s = &bufr[1]; 99*7c478bd9Sstevel@tonic-gate while (*str) 100*7c478bd9Sstevel@tonic-gate *s++ = *str++; 101*7c478bd9Sstevel@tonic-gate *s = '\0'; 102*7c478bd9Sstevel@tonic-gate if (*(--s) == '\n') 103*7c478bd9Sstevel@tonic-gate *s = '\0'; 104*7c478bd9Sstevel@tonic-gate len = strlen(bufr) + 1; 105*7c478bd9Sstevel@tonic-gate if ((i = len % xpacksize) != 0) { 106*7c478bd9Sstevel@tonic-gate len = len + xpacksize - i; 107*7c478bd9Sstevel@tonic-gate bufr[len - 1] = '\0'; 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate gwrblk(bufr, len); 110*7c478bd9Sstevel@tonic-gate return(0); 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 115*7c478bd9Sstevel@tonic-gate int 116*7c478bd9Sstevel@tonic-gate grdmsg(str, fn) 117*7c478bd9Sstevel@tonic-gate char *str; 118*7c478bd9Sstevel@tonic-gate { 119*7c478bd9Sstevel@tonic-gate unsigned len; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate if(setjmp(Gfailbuf)) 122*7c478bd9Sstevel@tonic-gate return(FAIL); 123*7c478bd9Sstevel@tonic-gate for (;;) { 124*7c478bd9Sstevel@tonic-gate len = pkread(str, packsize); 125*7c478bd9Sstevel@tonic-gate if (len == 0) 126*7c478bd9Sstevel@tonic-gate continue; 127*7c478bd9Sstevel@tonic-gate str += len; 128*7c478bd9Sstevel@tonic-gate if (*(str - 1) == '\0') 129*7c478bd9Sstevel@tonic-gate break; 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate return(0); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 136*7c478bd9Sstevel@tonic-gate int 137*7c478bd9Sstevel@tonic-gate gwrdata(fp1, fn) 138*7c478bd9Sstevel@tonic-gate FILE *fp1; 139*7c478bd9Sstevel@tonic-gate { 140*7c478bd9Sstevel@tonic-gate char bufr[BUFSIZ]; 141*7c478bd9Sstevel@tonic-gate int fd1; 142*7c478bd9Sstevel@tonic-gate int len; 143*7c478bd9Sstevel@tonic-gate int ret; 144*7c478bd9Sstevel@tonic-gate unsigned long bytes; 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate if(setjmp(Gfailbuf)) 147*7c478bd9Sstevel@tonic-gate return(FAIL); 148*7c478bd9Sstevel@tonic-gate bytes = 0L; 149*7c478bd9Sstevel@tonic-gate fd1 = fileno( fp1 ); 150*7c478bd9Sstevel@tonic-gate while ((len = read( fd1, bufr, BUFSIZ )) > 0) { 151*7c478bd9Sstevel@tonic-gate bytes += len; 152*7c478bd9Sstevel@tonic-gate putfilesize(bytes); 153*7c478bd9Sstevel@tonic-gate ret = gwrblk(bufr, len); 154*7c478bd9Sstevel@tonic-gate if (ret != len) { 155*7c478bd9Sstevel@tonic-gate return(FAIL); 156*7c478bd9Sstevel@tonic-gate } 157*7c478bd9Sstevel@tonic-gate if (len != BUFSIZ) 158*7c478bd9Sstevel@tonic-gate break; 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate ret = gwrblk(bufr, 0); 161*7c478bd9Sstevel@tonic-gate return(0); 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 165*7c478bd9Sstevel@tonic-gate int 166*7c478bd9Sstevel@tonic-gate grddata(fn, fp2) 167*7c478bd9Sstevel@tonic-gate FILE *fp2; 168*7c478bd9Sstevel@tonic-gate { 169*7c478bd9Sstevel@tonic-gate register int ret = SUCCESS; 170*7c478bd9Sstevel@tonic-gate int fd2; 171*7c478bd9Sstevel@tonic-gate int len; 172*7c478bd9Sstevel@tonic-gate char bufr[BUFSIZ]; 173*7c478bd9Sstevel@tonic-gate unsigned long bytes; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate if(setjmp(Gfailbuf)) 176*7c478bd9Sstevel@tonic-gate return(FAIL); 177*7c478bd9Sstevel@tonic-gate bytes = 0L; 178*7c478bd9Sstevel@tonic-gate fd2 = fileno( fp2 ); 179*7c478bd9Sstevel@tonic-gate for (;;) { 180*7c478bd9Sstevel@tonic-gate len = grdblk(bufr, BUFSIZ); 181*7c478bd9Sstevel@tonic-gate if (len < 0) { 182*7c478bd9Sstevel@tonic-gate return(FAIL); 183*7c478bd9Sstevel@tonic-gate } 184*7c478bd9Sstevel@tonic-gate bytes += len; 185*7c478bd9Sstevel@tonic-gate putfilesize(bytes); 186*7c478bd9Sstevel@tonic-gate if ( ret == SUCCESS && write( fd2, bufr, len ) != len) { 187*7c478bd9Sstevel@tonic-gate ret = errno; 188*7c478bd9Sstevel@tonic-gate DEBUG(7, "grddata: write to file failed, errno %d\n", errno); 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate if (len < BUFSIZ) 191*7c478bd9Sstevel@tonic-gate break; 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate return(ret); 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate static 198*7c478bd9Sstevel@tonic-gate int 199*7c478bd9Sstevel@tonic-gate grdblk(blk, len) 200*7c478bd9Sstevel@tonic-gate char *blk; 201*7c478bd9Sstevel@tonic-gate { 202*7c478bd9Sstevel@tonic-gate int i, ret; 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate for (i = 0; i < len; i += ret) { 205*7c478bd9Sstevel@tonic-gate ret = pkread(blk, len - i); 206*7c478bd9Sstevel@tonic-gate if (ret < 0) 207*7c478bd9Sstevel@tonic-gate return(FAIL); 208*7c478bd9Sstevel@tonic-gate blk += ret; 209*7c478bd9Sstevel@tonic-gate if (ret == 0) 210*7c478bd9Sstevel@tonic-gate return(i); 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate return(i); 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate static int 217*7c478bd9Sstevel@tonic-gate gwrblk(blk, len) 218*7c478bd9Sstevel@tonic-gate char *blk; 219*7c478bd9Sstevel@tonic-gate { 220*7c478bd9Sstevel@tonic-gate return(pkwrite(blk, len)); 221*7c478bd9Sstevel@tonic-gate } 222