1: #ifndef lint 2: static char sccsid[] = "@(#)gio.c 5.1 (Berkeley) 7/2/83"; 3: #endif 4: 5: #define USER 1 6: #include "pk.p" 7: #include <sys/types.h> 8: #include "pk.h" 9: #include <setjmp.h> 10: #include "uucp.h" 11: 12: extern time_t time(); 13: 14: 15: jmp_buf Failbuf; 16: 17: struct pack *Pk; 18: 19: pkfail() 20: { 21: longjmp(Failbuf, 1); 22: } 23: 24: gturnon() 25: { 26: int ret; 27: struct pack *pkopen(); 28: if (setjmp(Failbuf)) 29: return(FAIL); 30: if (Pkdrvon) { 31: ret = pkon(Ofn, PACKSIZE); 32: DEBUG(4, "pkon - %d ", ret); 33: DEBUG(4, "Ofn - %d\n", Ofn); 34: if (ret <= 0) 35: return(FAIL); 36: } 37: else { 38: if (Debug > 4) 39: pkdebug = 1; 40: Pk = pkopen(Ifn, Ofn); 41: if ((int) Pk == NULL) 42: return(FAIL); 43: } 44: return(0); 45: } 46: 47: 48: gturnoff() 49: { 50: if(setjmp(Failbuf)) 51: return(FAIL); 52: if (Pkdrvon) 53: pkoff(Ofn); 54: else 55: pkclose(Pk); 56: return(0); 57: } 58: 59: 60: gwrmsg(type, str, fn) 61: char type; 62: register char *str; 63: { 64: char bufr[BUFSIZ]; 65: register char *s; 66: int len, i; 67: 68: if(setjmp(Failbuf)) 69: return(FAIL); 70: bufr[0] = type; 71: s = &bufr[1]; 72: while (*str) 73: *s++ = *str++; 74: *s = '\0'; 75: if (*(--s) == '\n') 76: *s = '\0'; 77: len = strlen(bufr) + 1; 78: if ((i = len % PACKSIZE)) { 79: len = len + PACKSIZE - i; 80: bufr[len - 1] = '\0'; 81: } 82: gwrblk(bufr, len, fn); 83: return(0); 84: } 85: 86: 87: grdmsg(str, fn) 88: register char *str; 89: { 90: unsigned len; 91: 92: if(setjmp(Failbuf)) 93: return(FAIL); 94: for (;;) { 95: if (Pkdrvon) 96: len = read(fn, str, PACKSIZE); 97: else 98: len = pkread(Pk, str, PACKSIZE); 99: if (len == 0) 100: continue; 101: str += len; 102: if (*(str - 1) == '\0') 103: break; 104: } 105: return(0); 106: } 107: 108: 109: gwrdata(fp1, fn) 110: FILE *fp1; 111: { 112: char bufr[BUFSIZ]; 113: register int len; 114: int ret; 115: time_t t1, t2; 116: long bytes; 117: char text[BUFSIZ]; 118: 119: if(setjmp(Failbuf)) 120: return(FAIL); 121: bytes = 0L; 122: time(&t1); 123: while ((len = fread(bufr, sizeof (char), BUFSIZ, fp1)) > 0) { 124: bytes += len; 125: ret = gwrblk(bufr, len, fn); 126: if (ret != len) { 127: return(FAIL); 128: } 129: if (len != BUFSIZ) 130: break; 131: } 132: ret = gwrblk(bufr, 0, fn); 133: time(&t2); 134: sprintf(text, "sent data %ld bytes %ld secs", bytes, t2 - t1); 135: DEBUG(1, "%s\n", text); 136: syslog(text); 137: sysacct(bytes, t2 - t1); 138: return(0); 139: } 140: 141: 142: grddata(fn, fp2) 143: FILE *fp2; 144: { 145: register int len; 146: char bufr[BUFSIZ]; 147: time_t t1, t2; 148: long bytes; 149: char text[BUFSIZ]; 150: 151: if(setjmp(Failbuf)) 152: return(FAIL); 153: bytes = 0L; 154: time(&t1); 155: for (;;) { 156: len = grdblk(bufr, BUFSIZ, fn); 157: if (len < 0) { 158: return(FAIL); 159: } 160: bytes += len; 161: /* ittvax!swatt: check return value of fwrite */ 162: if (fwrite(bufr, sizeof (char), len, fp2) != len) 163: return(FAIL); 164: if (len < BUFSIZ) 165: break; 166: } 167: time(&t2); 168: sprintf(text, "received data %ld bytes %ld secs", bytes, t2 - t1); 169: DEBUG(1, "%s\n", text); 170: syslog(text); 171: sysacct(bytes, t2 - t1); 172: return(0); 173: } 174: 175: 176: /* call ultouch every TC calls to either grdblk or gwrblk -- rti!trt */ 177: #define TC 20 178: static int tc = TC; 179: 180: grdblk(blk, len, fn) 181: register int len; 182: char *blk; 183: { 184: register int i, ret; 185: 186: /* call ultouch occasionally -- rti!trt */ 187: if (--tc < 0) { 188: tc = TC; 189: ultouch(); 190: } 191: for (i = 0; i < len; i += ret) { 192: if (Pkdrvon) 193: ret = read(fn, blk, len - i); 194: else 195: ret = pkread(Pk, blk, len - i); 196: if (ret < 0) 197: return(FAIL); 198: blk += ret; 199: if (ret == 0) 200: return(i); 201: } 202: return(i); 203: } 204: 205: 206: gwrblk(blk, len, fn) 207: register char *blk; 208: { 209: register int ret; 210: 211: /* call ultouch occasionally -- rti!trt */ 212: if (--tc < 0) { 213: tc = TC; 214: ultouch(); 215: } 216: if (Pkdrvon) 217: ret = write(fn, blk, len); 218: else 219: ret = pkwrite(Pk, blk, len); 220: return(ret); 221: }