due.c 1.6 KB

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