xref: /csrg-svn/usr.bin/f77/libI77/due.c (revision 4114)
12490Sdlw /*
2*4114Sdlw char id_due[] = "@(#)due.c	1.3";
32490Sdlw  *
42490Sdlw  * direct unformatted external i/o
52490Sdlw  */
62490Sdlw 
72490Sdlw #include "fio.h"
82490Sdlw 
9*4114Sdlw char rdue[] = "read due";
10*4114Sdlw char wdue[] = "write due";
112490Sdlw 
122490Sdlw s_rdue(a) cilist *a;
132490Sdlw {
142490Sdlw 	int n;
152490Sdlw 	reading = YES;
162490Sdlw 	if(n=c_due(a,READ)) return(n);
17*4114Sdlw 	if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rdue);
182490Sdlw 	return(OK);
192490Sdlw }
202490Sdlw 
212490Sdlw s_wdue(a) cilist *a;
222490Sdlw {
232490Sdlw 	int n;
242490Sdlw 	reading = NO;
252490Sdlw 	if(n=c_due(a,WRITE)) return(n);
262490Sdlw 	curunit->uend = NO;
27*4114Sdlw 	if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wdue)
282490Sdlw 	return(OK);
292490Sdlw }
302490Sdlw 
312490Sdlw c_due(a,flag) cilist *a;
322490Sdlw {	int n;
332490Sdlw 	lfname = NULL;
342490Sdlw 	elist = NO;
352490Sdlw 	sequential=formatted=NO;
362490Sdlw 	recpos = reclen = 0;
372490Sdlw 	external = YES;
382490Sdlw 	errflag = a->cierr;
392490Sdlw 	endflag = a->ciend;
402490Sdlw 	lunit = a->ciunit;
41*4114Sdlw 	if(not_legal(lunit)) err(errflag,F_ERUNIT,rdue+5);
422490Sdlw 	curunit = &units[lunit];
432490Sdlw 	if (!curunit->ufd && (n=fk_open(flag,DIR,UNF,(ftnint)lunit)) )
44*4114Sdlw 		err(errflag,n,rdue+5)
452490Sdlw 	cf = curunit->ufd;
462490Sdlw 	elist = YES;
472490Sdlw 	lfname = curunit->ufnm;
48*4114Sdlw 	if (curunit->ufmt) err(errflag,F_ERNOUIO,rdue+5)
49*4114Sdlw 	if (!curunit->useek || !curunit->url) err(errflag,F_ERNODIO,rdue+5)
502490Sdlw 	if (fseek(cf, (long)((a->cirec-1)*curunit->url), 0) < 0)
51*4114Sdlw 		return(due_err(rdue+5));
522490Sdlw 	else
532490Sdlw 		return(OK);
542490Sdlw }
552490Sdlw 
562490Sdlw e_rdue()
572490Sdlw {
582490Sdlw 	return(OK);
592490Sdlw }
602490Sdlw 
612490Sdlw e_wdue()
622490Sdlw {/*	This is to ensure full records. It is really necessary. */
632490Sdlw 	int n = 0;
642490Sdlw 	if (curunit->url!=1 && recpos!=curunit->url &&
652490Sdlw 	    (fseek(cf, (long)(curunit->url-recpos-1), 1) < 0
662490Sdlw 		|| fwrite(&n, 1, 1, cf) != 1))
67*4114Sdlw 			return(due_err(rdue+5));
682490Sdlw 	return(OK);
692490Sdlw }
70