12503Sdlw /* 2*3634Sdlw char id_util[] = "@(#)util.c 1.3"; 32503Sdlw * 42503Sdlw * utility routines 52503Sdlw */ 62503Sdlw 72503Sdlw #include <sys/types.h> 82503Sdlw #include <sys/stat.h> 92503Sdlw #include "fio.h" 102503Sdlw 112503Sdlw 12*3634Sdlw ini_std(u,F,w,i66) FILE *F; 132503Sdlw { unit *p; 142503Sdlw p = &units[u]; 152503Sdlw p->ufd = F; 162503Sdlw p->ufnm = NULL; 172503Sdlw p->useek = canseek(F); 182503Sdlw p->ufmt = YES; 192503Sdlw p->uwrt = (w==WRITE)? YES : NO; 20*3634Sdlw p->ublnk = p->uscrtch = p->uend = NO; 21*3634Sdlw p->uprnt = (i66!=0)? YES : NO; 222503Sdlw p->url = 0; 232503Sdlw p->uinode = finode(F); 242503Sdlw } 252503Sdlw 262503Sdlw canseek(f) FILE *f; /*SYSDEP*/ 272503Sdlw { struct stat x; 282503Sdlw return( (fstat(fileno(f),&x)==0) && 292503Sdlw (x.st_nlink > 0 /*!pipe*/) && !isatty(fileno(f)) ); 302503Sdlw } 312503Sdlw 322503Sdlw nowreading(x) unit *x; 332503Sdlw { 342503Sdlw long loc; 352503Sdlw x->uwrt = NO; 362503Sdlw loc=ftell(x->ufd); 372503Sdlw freopen(x->ufnm,"r",x->ufd); 382503Sdlw fseek(x->ufd,loc,0); 392503Sdlw } 402503Sdlw 412503Sdlw nowwriting(x) unit *x; 422503Sdlw { 432503Sdlw long loc; 442503Sdlw x->uwrt = YES; 452503Sdlw loc=ftell(x->ufd); 462503Sdlw freopen(x->ufnm,"a",x->ufd); 472503Sdlw fseek(x->ufd,loc,0); 482503Sdlw } 492503Sdlw 502503Sdlw g_char(a,alen,b) char *a,*b; ftnlen alen; 512503Sdlw { char *x=a+alen-1, *y=b+alen-1; 522503Sdlw while (x >= a && *x == ' ') {x--; y--;} 532503Sdlw *(y+1) = '\0'; 542503Sdlw while (x >= a) *y-- = *x--; 552503Sdlw } 562503Sdlw 572503Sdlw b_char(from, to, tolen) char *from, *to; ftnlen tolen; 582503Sdlw { int i=0; 592503Sdlw while (*from && i < tolen) { 602503Sdlw *to++ = *from++; 612503Sdlw i++; 622503Sdlw } 632503Sdlw while (i++ < tolen) 642503Sdlw *to++ = ' '; 652503Sdlw } 662503Sdlw 672503Sdlw inode(a) char *a; 682503Sdlw { struct stat x; 692503Sdlw if(stat(a,&x)==0) return(x.st_ino); 702503Sdlw else return(-1); 712503Sdlw } 722503Sdlw 732503Sdlw finode(f) FILE *f; 742503Sdlw { struct stat x; 752503Sdlw if(fstat(fileno(f),&x)==0) return(x.st_ino); 762503Sdlw else return(-1); 772503Sdlw } 782503Sdlw 792503Sdlw char 802503Sdlw last_char(f) FILE *f; 812503Sdlw { 822503Sdlw fseek(f,-2L,1); 832503Sdlw if(ftell(f)) return(getc(f)); 842503Sdlw else return('\n'); 852503Sdlw } 86