|
|
1.1 root 1: /*
2: * sequential unformatted external read/write routines
3: */
4:
5: #include "fio.h"
6:
7: extern int reclen;
8: long recloc;
9: char *rsue = "read sue";
10: char *sue = "sue";
11:
12: s_rsue(a) cilist *a;
13: {
14: int n;
15: reading = YES;
16: if(n=c_sue(a,READ)) return(n);
17: if(curunit->uwrt) nowreading(curunit);
18: recpos = 0;
19: if(fread(&reclen,sizeof(int),1,cf) == 1) return(OK);
20: if(feof(cf))
21: { curunit->uend = YES;
22: err(endflag, EOF, rsue)
23: }
24: clearerr(cf);
25: err(errflag, errno, rsue)
26: }
27:
28: s_wsue(a) cilist *a;
29: {
30: int n;
31: reading = NO;
32: if(n=c_sue(a,WRITE)) return(n);
33: if(!curunit->uwrt) nowwriting(curunit);
34: reclen = 0;
35: recloc=ftell(cf);
36: fseek(cf,(long)sizeof(int),1);
37: curunit->uend = NO;
38: return(OK);
39: }
40:
41: c_sue(a,flag) cilist *a;
42: { int n;
43: external = sequential = YES;
44: formatted = NO;
45: lfname = NULL;
46: elist = NO;
47: errflag = a->cierr;
48: endflag = a->ciend;
49: lunit = a->ciunit;
50: if(not_legal(lunit)) err(errflag,101,sue)
51: curunit = &units[lunit];
52: if(!curunit->ufd && (n=fk_open(flag,SEQ,UNF,lunit))) err(errflag,n,sue);
53: cf = curunit->ufd;
54: elist = YES;
55: lfname = curunit->ufnm;
56: if(curunit->ufmt) err(errflag,103,sue)
57: if(curunit->url) err(errflag,105,sue)
58: if(!curunit->useek) err(errflag,120,sue)
59: return(OK);
60: }
61:
62: e_wsue()
63: { long loc;
64: fwrite(&reclen,sizeof(int),1,cf);
65: loc=ftell(cf);
66: fseek(cf,recloc,0);
67: fwrite(&reclen,sizeof(int),1,cf);
68: fseek(cf,loc,0);
69: return(OK);
70: }
71:
72: e_rsue()
73: {
74: fseek(cf,(long)(reclen-recpos+sizeof(int)),1);
75: return(OK);
76: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.