1 /* 2 char id_util[] = "@(#)util.c 1.8"; 3 * 4 * utility routines 5 */ 6 7 #include "fio.h" 8 9 extern short ccntrl_, blzero_; 10 11 nowreading(x) unit *x; 12 { 13 return(now_acc(x,"r")); 14 } 15 16 nowwriting(x) unit *x; 17 { 18 return(now_acc(x,"a")); 19 } 20 21 LOCAL now_acc(x,mode) 22 unit *x; char *mode; 23 { 24 long loc; 25 26 if (!x->ufnm) 27 { 28 errno = EBADF; 29 return(NO); 30 } 31 if (x->useek) 32 loc=ftell(x->ufd); 33 if (freopen(x->ufnm,mode,x->ufd)) 34 { 35 if (x->useek) 36 fseek(x->ufd,loc,0); 37 x->uwrt = (*mode=='a'); 38 return(YES); 39 } 40 if (x->ufd = fopen(x->ufnm, (*mode=='a')? "r":"a")) 41 if (x->useek) 42 fseek(x->ufd,loc,0); 43 return(NO); 44 } 45 46 g_char(a,alen,b) char *a,*b; ftnlen alen; 47 { char *x=a+alen-1, *y=b+alen-1; 48 while (x >= a && *x == ' ') {x--; y--;} 49 *(y+1) = '\0'; 50 while (x >= a) *y-- = *x--; 51 } 52 53 b_char(from, to, tolen) char *from, *to; ftnlen tolen; 54 { int i=0; 55 while (*from && i < tolen) { 56 *to++ = *from++; 57 i++; 58 } 59 while (i++ < tolen) 60 *to++ = ' '; 61 } 62 63 char 64 last_char(f) FILE *f; 65 { 66 fseek(f,-2L,1); 67 if(ftell(f)) return(getc(f)); 68 else return('\n'); 69 } 70