Commit | Line | Data |
---|---|---|
82492b51 KB |
1 | /*- |
2 | * Copyright (c) 1980 The Regents of the University of California. | |
3 | * All rights reserved. | |
9bbc979b | 4 | * |
ad787160 C |
5 | * This module is believed to contain source code proprietary to AT&T. |
6 | * Use and redistribution is subject to the Berkeley Software License | |
7 | * Agreement and your Software Agreement with AT&T (Western Electric). | |
161423a6 RE |
8 | */ |
9 | ||
82492b51 | 10 | #ifndef lint |
ad787160 | 11 | static char sccsid[] = "@(#)sue.c 5.3 (Berkeley) 4/12/91"; |
82492b51 KB |
12 | #endif /* not lint */ |
13 | ||
161423a6 | 14 | /* |
9bbc979b DW |
15 | * sequential unformatted external read/write routines |
16 | */ | |
17 | ||
18 | #include "fio.h" | |
19 | ||
20 | extern int reclen; | |
5e52dbf7 DL |
21 | LOCAL long recloc; |
22 | LOCAL char rsue[] = "read sue"; | |
23 | LOCAL char wsue[] = "write sue"; | |
9bbc979b DW |
24 | |
25 | s_rsue(a) cilist *a; | |
26 | { | |
27 | int n; | |
28 | reading = YES; | |
29 | if(n=c_sue(a,READ)) return(n); | |
3f0c29e0 | 30 | if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rsue) |
9bbc979b DW |
31 | recpos = 0; |
32 | if(fread(&reclen,sizeof(int),1,cf) == 1) return(OK); | |
33 | if(feof(cf)) | |
34 | { curunit->uend = YES; | |
35 | err(endflag, EOF, rsue) | |
36 | } | |
37 | clearerr(cf); | |
38 | err(errflag, errno, rsue) | |
39 | } | |
40 | ||
41 | s_wsue(a) cilist *a; | |
42 | { | |
43 | int n; | |
44 | reading = NO; | |
45 | if(n=c_sue(a,WRITE)) return(n); | |
3f0c29e0 | 46 | if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wsue) |
9bbc979b DW |
47 | reclen = 0; |
48 | recloc=ftell(cf); | |
49 | fseek(cf,(long)sizeof(int),1); | |
50 | curunit->uend = NO; | |
51 | return(OK); | |
52 | } | |
53 | ||
5e52dbf7 | 54 | LOCAL |
7784fa72 | 55 | c_sue(a,flg) cilist *a; |
9bbc979b DW |
56 | { int n; |
57 | external = sequential = YES; | |
58 | formatted = NO; | |
59 | lfname = NULL; | |
60 | elist = NO; | |
61 | errflag = a->cierr; | |
62 | endflag = a->ciend; | |
63 | lunit = a->ciunit; | |
3f0c29e0 | 64 | if(not_legal(lunit)) err(errflag,F_ERUNIT,rsue+5) |
9bbc979b | 65 | curunit = &units[lunit]; |
7784fa72 | 66 | if(!curunit->ufd && (n=fk_open(flg,SEQ,UNF,(ftnint)lunit))) |
3f0c29e0 | 67 | err(errflag,n,rsue+5) |
9bbc979b DW |
68 | cf = curunit->ufd; |
69 | elist = YES; | |
70 | lfname = curunit->ufnm; | |
3f0c29e0 DW |
71 | if(curunit->ufmt) err(errflag,F_ERNOUIO,rsue+5) |
72 | if(curunit->url) err(errflag,F_ERNOSIO,rsue+5) | |
73 | if(!curunit->useek) err(errflag,F_ERSEEK,rsue+5) | |
9bbc979b DW |
74 | return(OK); |
75 | } | |
76 | ||
77 | e_wsue() | |
78 | { long loc; | |
79 | fwrite(&reclen,sizeof(int),1,cf); | |
80 | loc=ftell(cf); | |
81 | fseek(cf,recloc,0); | |
82 | fwrite(&reclen,sizeof(int),1,cf); | |
83 | fseek(cf,loc,0); | |
84 | return(OK); | |
85 | } | |
86 | ||
87 | e_rsue() | |
88 | { | |
89 | fseek(cf,(long)(reclen-recpos+sizeof(int)),1); | |
90 | return(OK); | |
91 | } |