|
|
1.1 ! root 1: /* ! 2: * utility routines ! 3: */ ! 4: ! 5: #include <sys/types.h> ! 6: #include <sys/stat.h> ! 7: #include "fio.h" ! 8: ! 9: ! 10: ini_std(u,F,w) FILE *F; ! 11: { unit *p; ! 12: p = &units[u]; ! 13: p->ufd = F; ! 14: p->ufnm = NULL; ! 15: p->useek = canseek(F); ! 16: p->ufmt = YES; ! 17: p->uwrt = (w==WRITE)? YES : NO; ! 18: p->ublnk = p->uscrtch = p->uprnt = p->uend = NO; ! 19: p->url = 0; ! 20: p->uinode = finode(F); ! 21: } ! 22: ! 23: canseek(f) FILE *f; /*SYSDEP*/ ! 24: { struct stat x; ! 25: return( (fstat(fileno(f),&x)==0) && ! 26: (x.st_nlink > 0 /*!pipe*/) && !isatty(fileno(f)) ); ! 27: } ! 28: ! 29: nowreading(x) unit *x; ! 30: { ! 31: long loc; ! 32: x->uwrt = NO; ! 33: loc=ftell(x->ufd); ! 34: freopen(x->ufnm,"r",x->ufd); ! 35: fseek(x->ufd,loc,0); ! 36: } ! 37: ! 38: nowwriting(x) unit *x; ! 39: { ! 40: long loc; ! 41: x->uwrt = YES; ! 42: loc=ftell(x->ufd); ! 43: freopen(x->ufnm,"a",x->ufd); ! 44: fseek(x->ufd,loc,0); ! 45: } ! 46: ! 47: g_char(a,alen,b) char *a,*b; ftnlen alen; ! 48: { char *x=a+alen-1, *y=b+alen-1; ! 49: while (x >= a && *x == ' ') {x--; y--;} ! 50: *(y+1) = '\0'; ! 51: while (x >= a) *y-- = *x--; ! 52: } ! 53: ! 54: b_char(from, to, tolen) char *from, *to; ftnlen tolen; ! 55: { int i=0; ! 56: while (*from && i < tolen) { ! 57: *to++ = *from++; ! 58: i++; ! 59: } ! 60: while (i++ < tolen) ! 61: *to++ = ' '; ! 62: } ! 63: ! 64: inode(a) char *a; ! 65: { struct stat x; ! 66: if(stat(a,&x)==0) return(x.st_ino); ! 67: else return(-1); ! 68: } ! 69: ! 70: finode(f) FILE *f; ! 71: { struct stat x; ! 72: if(fstat(fileno(f),&x)==0) return(x.st_ino); ! 73: else return(-1); ! 74: } ! 75: ! 76: char ! 77: last_char(f) FILE *f; ! 78: { ! 79: fseek(f,-2L,1); ! 80: if(ftell(f)) return(getc(f)); ! 81: else return('\n'); ! 82: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.