1*47943Sbostic /*-
2*47943Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*47943Sbostic * All rights reserved.
42490Sdlw *
5*47943Sbostic * %sccs.include.proprietary.c%
623071Skre */
723071Skre
8*47943Sbostic #ifndef lint
9*47943Sbostic static char sccsid[] = "@(#)due.c 5.3 (Berkeley) 04/12/91";
10*47943Sbostic #endif /* not lint */
11*47943Sbostic
1223071Skre /*
132490Sdlw * direct unformatted external i/o
142490Sdlw */
152490Sdlw
162490Sdlw #include "fio.h"
172490Sdlw
1820984Slibs LOCAL char rdue[] = "read due";
1920984Slibs LOCAL char wdue[] = "write due";
202490Sdlw
s_rdue(a)212490Sdlw s_rdue(a) cilist *a;
222490Sdlw {
232490Sdlw int n;
242490Sdlw reading = YES;
252490Sdlw if(n=c_due(a,READ)) return(n);
264114Sdlw if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rdue);
272490Sdlw return(OK);
282490Sdlw }
292490Sdlw
s_wdue(a)302490Sdlw s_wdue(a) cilist *a;
312490Sdlw {
322490Sdlw int n;
332490Sdlw reading = NO;
342490Sdlw if(n=c_due(a,WRITE)) return(n);
352490Sdlw curunit->uend = NO;
364114Sdlw if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wdue)
372490Sdlw return(OK);
382490Sdlw }
392490Sdlw
4020984Slibs LOCAL
c_due(a,flg)4140228Sdonn c_due(a,flg) cilist *a;
422490Sdlw { int n;
432490Sdlw lfname = NULL;
442490Sdlw elist = NO;
452490Sdlw sequential=formatted=NO;
462490Sdlw recpos = reclen = 0;
472490Sdlw external = YES;
482490Sdlw errflag = a->cierr;
492490Sdlw endflag = a->ciend;
502490Sdlw lunit = a->ciunit;
514114Sdlw if(not_legal(lunit)) err(errflag,F_ERUNIT,rdue+5);
522490Sdlw curunit = &units[lunit];
5340228Sdonn if (!curunit->ufd && (n=fk_open(flg,DIR,UNF,(ftnint)lunit)) )
544114Sdlw err(errflag,n,rdue+5)
552490Sdlw cf = curunit->ufd;
562490Sdlw elist = YES;
572490Sdlw lfname = curunit->ufnm;
584114Sdlw if (curunit->ufmt) err(errflag,F_ERNOUIO,rdue+5)
594114Sdlw if (!curunit->useek || !curunit->url) err(errflag,F_ERNODIO,rdue+5)
602490Sdlw if (fseek(cf, (long)((a->cirec-1)*curunit->url), 0) < 0)
614114Sdlw return(due_err(rdue+5));
622490Sdlw else
632490Sdlw return(OK);
642490Sdlw }
652490Sdlw
e_rdue()662490Sdlw e_rdue()
672490Sdlw {
682490Sdlw return(OK);
692490Sdlw }
702490Sdlw
e_wdue()712490Sdlw e_wdue()
722490Sdlw {/* This is to ensure full records. It is really necessary. */
732490Sdlw int n = 0;
742490Sdlw if (curunit->url!=1 && recpos!=curunit->url &&
752490Sdlw (fseek(cf, (long)(curunit->url-recpos-1), 1) < 0
762490Sdlw || fwrite(&n, 1, 1, cf) != 1))
774114Sdlw return(due_err(rdue+5));
782490Sdlw return(OK);
792490Sdlw }
80