Commit | Line | Data |
---|---|---|
9bbc979b | 1 | /* |
161423a6 RE |
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. | |
9bbc979b | 5 | * |
7784fa72 | 6 | * @(#)sue.c 5.2 %G% |
161423a6 RE |
7 | */ |
8 | ||
9 | /* | |
9bbc979b DW |
10 | * sequential unformatted external read/write routines |
11 | */ | |
12 | ||
13 | #include "fio.h" | |
14 | ||
15 | extern int reclen; | |
5e52dbf7 DL |
16 | LOCAL long recloc; |
17 | LOCAL char rsue[] = "read sue"; | |
18 | LOCAL char wsue[] = "write sue"; | |
9bbc979b DW |
19 | |
20 | s_rsue(a) cilist *a; | |
21 | { | |
22 | int n; | |
23 | reading = YES; | |
24 | if(n=c_sue(a,READ)) return(n); | |
3f0c29e0 | 25 | if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rsue) |
9bbc979b DW |
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); | |
3f0c29e0 | 41 | if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wsue) |
9bbc979b DW |
42 | reclen = 0; |
43 | recloc=ftell(cf); | |
44 | fseek(cf,(long)sizeof(int),1); | |
45 | curunit->uend = NO; | |
46 | return(OK); | |
47 | } | |
48 | ||
5e52dbf7 | 49 | LOCAL |
7784fa72 | 50 | c_sue(a,flg) cilist *a; |
9bbc979b DW |
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; | |
3f0c29e0 | 59 | if(not_legal(lunit)) err(errflag,F_ERUNIT,rsue+5) |
9bbc979b | 60 | curunit = &units[lunit]; |
7784fa72 | 61 | if(!curunit->ufd && (n=fk_open(flg,SEQ,UNF,(ftnint)lunit))) |
3f0c29e0 | 62 | err(errflag,n,rsue+5) |
9bbc979b DW |
63 | cf = curunit->ufd; |
64 | elist = YES; | |
65 | lfname = curunit->ufnm; | |
3f0c29e0 DW |
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) | |
9bbc979b DW |
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 | } |