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

Defined functions

grdblk defined in line 200; used 1 times
grddata defined in line 139; used 2 times
grdmsg defined in line 67; used 2 times
gturnoff defined in line 31; used 2 times
gturnon defined in line 19; used 2 times
gwrblk defined in line 225; used 3 times
gwrdata defined in line 86; used 2 times
gwrmsg defined in line 40; used 2 times
pkfail defined in line 14; used 7 times

Defined variables

Failbuf defined in line 9; used 11 times
Pk defined in line 12; used 6 times
Retries defined in line 11; used 7 times
sccsid defined in line 2; never used
tc defined in line 196; used 4 times

Defined macros

TC defined in line 195; used 3 times
Last modified: 1986-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1421
Valid CSS Valid XHTML 1.0 Strict