12490Sdlw /* 223071Skre * Copyright (c) 1980 Regents of the University of California. 323071Skre * All rights reserved. The Berkeley software License Agreement 423071Skre * specifies the terms and conditions for redistribution. 52490Sdlw * 6*40228Sdonn * @(#)due.c 5.2 02/25/90 723071Skre */ 823071Skre 923071Skre /* 102490Sdlw * direct unformatted external i/o 112490Sdlw */ 122490Sdlw 132490Sdlw #include "fio.h" 142490Sdlw 1520984Slibs LOCAL char rdue[] = "read due"; 1620984Slibs LOCAL char wdue[] = "write due"; 172490Sdlw 182490Sdlw s_rdue(a) cilist *a; 192490Sdlw { 202490Sdlw int n; 212490Sdlw reading = YES; 222490Sdlw if(n=c_due(a,READ)) return(n); 234114Sdlw if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rdue); 242490Sdlw return(OK); 252490Sdlw } 262490Sdlw 272490Sdlw s_wdue(a) cilist *a; 282490Sdlw { 292490Sdlw int n; 302490Sdlw reading = NO; 312490Sdlw if(n=c_due(a,WRITE)) return(n); 322490Sdlw curunit->uend = NO; 334114Sdlw if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wdue) 342490Sdlw return(OK); 352490Sdlw } 362490Sdlw 3720984Slibs LOCAL 38*40228Sdonn c_due(a,flg) cilist *a; 392490Sdlw { int n; 402490Sdlw lfname = NULL; 412490Sdlw elist = NO; 422490Sdlw sequential=formatted=NO; 432490Sdlw recpos = reclen = 0; 442490Sdlw external = YES; 452490Sdlw errflag = a->cierr; 462490Sdlw endflag = a->ciend; 472490Sdlw lunit = a->ciunit; 484114Sdlw if(not_legal(lunit)) err(errflag,F_ERUNIT,rdue+5); 492490Sdlw curunit = &units[lunit]; 50*40228Sdonn if (!curunit->ufd && (n=fk_open(flg,DIR,UNF,(ftnint)lunit)) ) 514114Sdlw err(errflag,n,rdue+5) 522490Sdlw cf = curunit->ufd; 532490Sdlw elist = YES; 542490Sdlw lfname = curunit->ufnm; 554114Sdlw if (curunit->ufmt) err(errflag,F_ERNOUIO,rdue+5) 564114Sdlw if (!curunit->useek || !curunit->url) err(errflag,F_ERNODIO,rdue+5) 572490Sdlw if (fseek(cf, (long)((a->cirec-1)*curunit->url), 0) < 0) 584114Sdlw return(due_err(rdue+5)); 592490Sdlw else 602490Sdlw return(OK); 612490Sdlw } 622490Sdlw 632490Sdlw e_rdue() 642490Sdlw { 652490Sdlw return(OK); 662490Sdlw } 672490Sdlw 682490Sdlw e_wdue() 692490Sdlw {/* This is to ensure full records. It is really necessary. */ 702490Sdlw int n = 0; 712490Sdlw if (curunit->url!=1 && recpos!=curunit->url && 722490Sdlw (fseek(cf, (long)(curunit->url-recpos-1), 1) < 0 732490Sdlw || fwrite(&n, 1, 1, cf) != 1)) 744114Sdlw return(due_err(rdue+5)); 752490Sdlw return(OK); 762490Sdlw } 77