xref: /original-bsd/usr.bin/f77/libI77/due.c (revision c1946e27)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)due.c	5.3 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 /*
13  * direct unformatted external i/o
14  */
15 
16 #include "fio.h"
17 
18 LOCAL char rdue[] = "read due";
19 LOCAL char wdue[] = "write due";
20 
21 s_rdue(a) cilist *a;
22 {
23 	int n;
24 	reading = YES;
25 	if(n=c_due(a,READ)) return(n);
26 	if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rdue);
27 	return(OK);
28 }
29 
30 s_wdue(a) cilist *a;
31 {
32 	int n;
33 	reading = NO;
34 	if(n=c_due(a,WRITE)) return(n);
35 	curunit->uend = NO;
36 	if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wdue)
37 	return(OK);
38 }
39 
40 LOCAL
41 c_due(a,flg) cilist *a;
42 {	int n;
43 	lfname = NULL;
44 	elist = NO;
45 	sequential=formatted=NO;
46 	recpos = reclen = 0;
47 	external = YES;
48 	errflag = a->cierr;
49 	endflag = a->ciend;
50 	lunit = a->ciunit;
51 	if(not_legal(lunit)) err(errflag,F_ERUNIT,rdue+5);
52 	curunit = &units[lunit];
53 	if (!curunit->ufd && (n=fk_open(flg,DIR,UNF,(ftnint)lunit)) )
54 		err(errflag,n,rdue+5)
55 	cf = curunit->ufd;
56 	elist = YES;
57 	lfname = curunit->ufnm;
58 	if (curunit->ufmt) err(errflag,F_ERNOUIO,rdue+5)
59 	if (!curunit->useek || !curunit->url) err(errflag,F_ERNODIO,rdue+5)
60 	if (fseek(cf, (long)((a->cirec-1)*curunit->url), 0) < 0)
61 		return(due_err(rdue+5));
62 	else
63 		return(OK);
64 }
65 
66 e_rdue()
67 {
68 	return(OK);
69 }
70 
71 e_wdue()
72 {/*	This is to ensure full records. It is really necessary. */
73 	int n = 0;
74 	if (curunit->url!=1 && recpos!=curunit->url &&
75 	    (fseek(cf, (long)(curunit->url-recpos-1), 1) < 0
76 		|| fwrite(&n, 1, 1, cf) != 1))
77 			return(due_err(rdue+5));
78 	return(OK);
79 }
80