BSD 4_2 release
[unix-history] / usr / src / usr.lib / libI77 / due.c
CommitLineData
d8e03d41 1/*
a5486586 2char id_due[] = "@(#)due.c 1.3";
d8e03d41
DW
3 *
4 * direct unformatted external i/o
5 */
6
7#include "fio.h"
8
a5486586
DW
9char rdue[] = "read due";
10char wdue[] = "write due";
d8e03d41
DW
11
12s_rdue(a) cilist *a;
13{
14 int n;
15 reading = YES;
16 if(n=c_due(a,READ)) return(n);
a5486586 17 if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rdue);
d8e03d41
DW
18 return(OK);
19}
20
21s_wdue(a) cilist *a;
22{
23 int n;
24 reading = NO;
25 if(n=c_due(a,WRITE)) return(n);
26 curunit->uend = NO;
a5486586 27 if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wdue)
d8e03d41
DW
28 return(OK);
29}
30
31c_due(a,flag) cilist *a;
32{ int n;
33 lfname = NULL;
34 elist = NO;
35 sequential=formatted=NO;
36 recpos = reclen = 0;
37 external = YES;
38 errflag = a->cierr;
39 endflag = a->ciend;
40 lunit = a->ciunit;
a5486586 41 if(not_legal(lunit)) err(errflag,F_ERUNIT,rdue+5);
d8e03d41
DW
42 curunit = &units[lunit];
43 if (!curunit->ufd && (n=fk_open(flag,DIR,UNF,(ftnint)lunit)) )
a5486586 44 err(errflag,n,rdue+5)
d8e03d41
DW
45 cf = curunit->ufd;
46 elist = YES;
47 lfname = curunit->ufnm;
a5486586
DW
48 if (curunit->ufmt) err(errflag,F_ERNOUIO,rdue+5)
49 if (!curunit->useek || !curunit->url) err(errflag,F_ERNODIO,rdue+5)
d8e03d41 50 if (fseek(cf, (long)((a->cirec-1)*curunit->url), 0) < 0)
a5486586 51 return(due_err(rdue+5));
d8e03d41
DW
52 else
53 return(OK);
54}
55
56e_rdue()
57{
58 return(OK);
59}
60
61e_wdue()
62{/* This is to ensure full records. It is really necessary. */
63 int n = 0;
64 if (curunit->url!=1 && recpos!=curunit->url &&
65 (fseek(cf, (long)(curunit->url-recpos-1), 1) < 0
66 || fwrite(&n, 1, 1, cf) != 1))
a5486586 67 return(due_err(rdue+5));
d8e03d41
DW
68 return(OK);
69}