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