Commit | Line | Data |
---|---|---|
9bbc979b | 1 | /* |
3f0c29e0 | 2 | char id_sue[] = "@(#)sue.c 1.3"; |
9bbc979b DW |
3 | * |
4 | * sequential unformatted external read/write routines | |
5 | */ | |
6 | ||
7 | #include "fio.h" | |
8 | ||
9 | extern int reclen; | |
10 | long recloc; | |
3f0c29e0 DW |
11 | char rsue[] = "read sue"; |
12 | char wsue[] = "write sue"; | |
9bbc979b DW |
13 | |
14 | s_rsue(a) cilist *a; | |
15 | { | |
16 | int n; | |
17 | reading = YES; | |
18 | if(n=c_sue(a,READ)) return(n); | |
3f0c29e0 | 19 | if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rsue) |
9bbc979b DW |
20 | recpos = 0; |
21 | if(fread(&reclen,sizeof(int),1,cf) == 1) return(OK); | |
22 | if(feof(cf)) | |
23 | { curunit->uend = YES; | |
24 | err(endflag, EOF, rsue) | |
25 | } | |
26 | clearerr(cf); | |
27 | err(errflag, errno, rsue) | |
28 | } | |
29 | ||
30 | s_wsue(a) cilist *a; | |
31 | { | |
32 | int n; | |
33 | reading = NO; | |
34 | if(n=c_sue(a,WRITE)) return(n); | |
3f0c29e0 | 35 | if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wsue) |
9bbc979b DW |
36 | reclen = 0; |
37 | recloc=ftell(cf); | |
38 | fseek(cf,(long)sizeof(int),1); | |
39 | curunit->uend = NO; | |
40 | return(OK); | |
41 | } | |
42 | ||
43 | c_sue(a,flag) cilist *a; | |
44 | { int n; | |
45 | external = sequential = YES; | |
46 | formatted = NO; | |
47 | lfname = NULL; | |
48 | elist = NO; | |
49 | errflag = a->cierr; | |
50 | endflag = a->ciend; | |
51 | lunit = a->ciunit; | |
3f0c29e0 | 52 | if(not_legal(lunit)) err(errflag,F_ERUNIT,rsue+5) |
9bbc979b DW |
53 | curunit = &units[lunit]; |
54 | if(!curunit->ufd && (n=fk_open(flag,SEQ,UNF,(ftnint)lunit))) | |
3f0c29e0 | 55 | err(errflag,n,rsue+5) |
9bbc979b DW |
56 | cf = curunit->ufd; |
57 | elist = YES; | |
58 | lfname = curunit->ufnm; | |
3f0c29e0 DW |
59 | if(curunit->ufmt) err(errflag,F_ERNOUIO,rsue+5) |
60 | if(curunit->url) err(errflag,F_ERNOSIO,rsue+5) | |
61 | if(!curunit->useek) err(errflag,F_ERSEEK,rsue+5) | |
9bbc979b DW |
62 | return(OK); |
63 | } | |
64 | ||
65 | e_wsue() | |
66 | { long loc; | |
67 | fwrite(&reclen,sizeof(int),1,cf); | |
68 | loc=ftell(cf); | |
69 | fseek(cf,recloc,0); | |
70 | fwrite(&reclen,sizeof(int),1,cf); | |
71 | fseek(cf,loc,0); | |
72 | return(OK); | |
73 | } | |
74 | ||
75 | e_rsue() | |
76 | { | |
77 | fseek(cf,(long)(reclen-recpos+sizeof(int)),1); | |
78 | return(OK); | |
79 | } |