[16959] | 1 | #include "config.h" |
---|
[14547] | 2 | #include "f2c.h" |
---|
| 3 | #include "fio.h" |
---|
| 4 | |
---|
| 5 | #ifdef KR_headers |
---|
| 6 | c_due(a) cilist *a; |
---|
| 7 | #else |
---|
| 8 | c_due(cilist *a) |
---|
| 9 | #endif |
---|
| 10 | { |
---|
| 11 | if(f__init != 1) f_init(); |
---|
| 12 | f__init = 3; |
---|
| 13 | if(a->ciunit>=MXUNIT || a->ciunit<0) |
---|
| 14 | err(a->cierr,101,"startio"); |
---|
| 15 | f__sequential=f__formatted=f__recpos=0; |
---|
| 16 | f__external=1; |
---|
| 17 | f__curunit = &f__units[a->ciunit]; |
---|
| 18 | if(a->ciunit>=MXUNIT || a->ciunit<0) |
---|
| 19 | err(a->cierr,101,"startio"); |
---|
| 20 | f__elist=a; |
---|
| 21 | if(f__curunit->ufd==NULL && fk_open(DIR,UNF,a->ciunit) ) err(a->cierr,104,"due"); |
---|
| 22 | f__cf=f__curunit->ufd; |
---|
| 23 | if(f__curunit->ufmt) err(a->cierr,102,"cdue"); |
---|
| 24 | if(!f__curunit->useek) err(a->cierr,104,"cdue"); |
---|
| 25 | if(f__curunit->ufd==NULL) err(a->cierr,114,"cdue"); |
---|
| 26 | if(a->cirec <= 0) |
---|
| 27 | err(a->cierr,130,"due"); |
---|
[18476] | 28 | FSEEK(f__cf,(off_t)(a->cirec-1)*f__curunit->url,SEEK_SET); |
---|
[14547] | 29 | f__curunit->uend = 0; |
---|
| 30 | return(0); |
---|
| 31 | } |
---|
| 32 | #ifdef KR_headers |
---|
| 33 | integer s_rdue(a) cilist *a; |
---|
| 34 | #else |
---|
| 35 | integer s_rdue(cilist *a) |
---|
| 36 | #endif |
---|
| 37 | { |
---|
| 38 | int n; |
---|
| 39 | f__reading=1; |
---|
| 40 | if(n=c_due(a)) return(n); |
---|
| 41 | if(f__curunit->uwrt && f__nowreading(f__curunit)) |
---|
| 42 | err(a->cierr,errno,"read start"); |
---|
| 43 | return(0); |
---|
| 44 | } |
---|
| 45 | #ifdef KR_headers |
---|
| 46 | integer s_wdue(a) cilist *a; |
---|
| 47 | #else |
---|
| 48 | integer s_wdue(cilist *a) |
---|
| 49 | #endif |
---|
| 50 | { |
---|
| 51 | int n; |
---|
| 52 | f__reading=0; |
---|
| 53 | if(n=c_due(a)) return(n); |
---|
| 54 | if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit)) |
---|
| 55 | err(a->cierr,errno,"write start"); |
---|
| 56 | return(0); |
---|
| 57 | } |
---|
| 58 | integer e_rdue(Void) |
---|
| 59 | { |
---|
| 60 | f__init = 1; |
---|
| 61 | if(f__curunit->url==1 || f__recpos==f__curunit->url) |
---|
| 62 | return(0); |
---|
[18476] | 63 | FSEEK(f__cf,(off_t)(f__curunit->url-f__recpos),SEEK_CUR); |
---|
| 64 | if(FTELL(f__cf)%f__curunit->url) |
---|
[14547] | 65 | err(f__elist->cierr,200,"syserr"); |
---|
| 66 | return(0); |
---|
| 67 | } |
---|
| 68 | integer e_wdue(Void) |
---|
| 69 | { |
---|
| 70 | f__init = 1; |
---|
| 71 | #ifdef ALWAYS_FLUSH |
---|
| 72 | if (fflush(f__cf)) |
---|
| 73 | err(f__elist->cierr,errno,"write end"); |
---|
| 74 | #endif |
---|
| 75 | return(e_rdue()); |
---|
| 76 | } |
---|