|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: * ! 6: * @(#)sue.c 5.2 2/25/90 ! 7: */ ! 8: ! 9: /* ! 10: * sequential unformatted external read/write routines ! 11: */ ! 12: ! 13: #include "fio.h" ! 14: ! 15: extern int reclen; ! 16: LOCAL long recloc; ! 17: LOCAL char rsue[] = "read sue"; ! 18: LOCAL char wsue[] = "write sue"; ! 19: ! 20: s_rsue(a) cilist *a; ! 21: { ! 22: int n; ! 23: reading = YES; ! 24: if(n=c_sue(a,READ)) return(n); ! 25: if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rsue) ! 26: recpos = 0; ! 27: if(fread(&reclen,sizeof(int),1,cf) == 1) return(OK); ! 28: if(feof(cf)) ! 29: { curunit->uend = YES; ! 30: err(endflag, EOF, rsue) ! 31: } ! 32: clearerr(cf); ! 33: err(errflag, errno, rsue) ! 34: } ! 35: ! 36: s_wsue(a) cilist *a; ! 37: { ! 38: int n; ! 39: reading = NO; ! 40: if(n=c_sue(a,WRITE)) return(n); ! 41: if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wsue) ! 42: reclen = 0; ! 43: recloc=ftell(cf); ! 44: fseek(cf,(long)sizeof(int),1); ! 45: curunit->uend = NO; ! 46: return(OK); ! 47: } ! 48: ! 49: LOCAL ! 50: c_sue(a,flg) cilist *a; ! 51: { int n; ! 52: external = sequential = YES; ! 53: formatted = NO; ! 54: lfname = NULL; ! 55: elist = NO; ! 56: errflag = a->cierr; ! 57: endflag = a->ciend; ! 58: lunit = a->ciunit; ! 59: if(not_legal(lunit)) err(errflag,F_ERUNIT,rsue+5) ! 60: curunit = &units[lunit]; ! 61: if(!curunit->ufd && (n=fk_open(flg,SEQ,UNF,(ftnint)lunit))) ! 62: err(errflag,n,rsue+5) ! 63: cf = curunit->ufd; ! 64: elist = YES; ! 65: lfname = curunit->ufnm; ! 66: if(curunit->ufmt) err(errflag,F_ERNOUIO,rsue+5) ! 67: if(curunit->url) err(errflag,F_ERNOSIO,rsue+5) ! 68: if(!curunit->useek) err(errflag,F_ERSEEK,rsue+5) ! 69: return(OK); ! 70: } ! 71: ! 72: e_wsue() ! 73: { long loc; ! 74: fwrite(&reclen,sizeof(int),1,cf); ! 75: loc=ftell(cf); ! 76: fseek(cf,recloc,0); ! 77: fwrite(&reclen,sizeof(int),1,cf); ! 78: fseek(cf,loc,0); ! 79: return(OK); ! 80: } ! 81: ! 82: e_rsue() ! 83: { ! 84: fseek(cf,(long)(reclen-recpos+sizeof(int)),1); ! 85: return(OK); ! 86: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.