uio.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "f2c.h"
  2. #include "fio.h"
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. uiolen f__reclen;
  7. int
  8. #ifdef KR_headers
  9. do_us(number,ptr,len) ftnint *number; char *ptr; ftnlen len;
  10. #else
  11. do_us(ftnint *number, char *ptr, ftnlen len)
  12. #endif
  13. {
  14. if(f__reading)
  15. {
  16. f__recpos += (int)(*number * len);
  17. if(f__recpos>f__reclen)
  18. err(f__elist->cierr, 110, "do_us");
  19. if (fread(ptr,(int)len,(int)(*number),f__cf) != *number)
  20. err(f__elist->ciend, EOF, "do_us");
  21. return(0);
  22. }
  23. else
  24. {
  25. f__reclen += *number * len;
  26. (void) fwrite(ptr,(int)len,(int)(*number),f__cf);
  27. return(0);
  28. }
  29. }
  30. #ifdef KR_headers
  31. integer do_ud(number,ptr,len) ftnint *number; char *ptr; ftnlen len;
  32. #else
  33. integer do_ud(ftnint *number, char *ptr, ftnlen len)
  34. #endif
  35. {
  36. f__recpos += (int)(*number * len);
  37. if(f__recpos > f__curunit->url && f__curunit->url!=1)
  38. err(f__elist->cierr,110,"do_ud");
  39. if(f__reading)
  40. {
  41. #ifdef Pad_UDread
  42. #ifdef KR_headers
  43. int i;
  44. #else
  45. size_t i;
  46. #endif
  47. if (!(i = fread(ptr,(int)len,(int)(*number),f__cf))
  48. && !(f__recpos - *number*len))
  49. err(f__elist->cierr,EOF,"do_ud")
  50. if (i < *number)
  51. memset(ptr + i*len, 0, (*number - i)*len);
  52. return 0;
  53. #else
  54. if(fread(ptr,(int)len,(int)(*number),f__cf) != *number)
  55. err(f__elist->cierr,EOF,"do_ud")
  56. else return(0);
  57. #endif
  58. }
  59. (void) fwrite(ptr,(int)len,(int)(*number),f__cf);
  60. return(0);
  61. }
  62. #ifdef KR_headers
  63. integer do_uio(number,ptr,len) ftnint *number; char *ptr; ftnlen len;
  64. #else
  65. integer do_uio(ftnint *number, char *ptr, ftnlen len)
  66. #endif
  67. {
  68. if(f__sequential)
  69. return(do_us(number,ptr,len));
  70. else return(do_ud(number,ptr,len));
  71. }
  72. #ifdef __cplusplus
  73. }
  74. #endif