close.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "f2c.h"
  2. #include "fio.h"
  3. #ifdef KR_headers
  4. integer f_clos(a) cllist *a;
  5. #else
  6. #undef abs
  7. #undef min
  8. #undef max
  9. #include "stdlib.h"
  10. #ifdef NON_UNIX_STDIO
  11. #ifndef unlink
  12. #define unlink remove
  13. #endif
  14. #else
  15. #ifdef MSDOS
  16. #include "io.h"
  17. #else
  18. #ifdef __cplusplus
  19. extern "C" int unlink(const char*);
  20. #else
  21. extern int unlink(const char*);
  22. #endif
  23. #endif
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. integer f_clos(cllist *a)
  29. #endif
  30. { unit *b;
  31. if(a->cunit >= MXUNIT) return(0);
  32. b= &f__units[a->cunit];
  33. if(b->ufd==NULL)
  34. goto done;
  35. if (b->uscrtch == 1)
  36. goto Delete;
  37. if (!a->csta)
  38. goto Keep;
  39. switch(*a->csta) {
  40. default:
  41. Keep:
  42. case 'k':
  43. case 'K':
  44. if(b->uwrt == 1)
  45. t_runc((alist *)a);
  46. if(b->ufnm) {
  47. fclose(b->ufd);
  48. free(b->ufnm);
  49. }
  50. break;
  51. case 'd':
  52. case 'D':
  53. Delete:
  54. fclose(b->ufd);
  55. if(b->ufnm) {
  56. unlink(b->ufnm); /*SYSDEP*/
  57. free(b->ufnm);
  58. }
  59. }
  60. b->ufd=NULL;
  61. done:
  62. b->uend=0;
  63. b->ufnm=NULL;
  64. return(0);
  65. }
  66. void
  67. #ifdef KR_headers
  68. f_exit()
  69. #else
  70. f_exit(void)
  71. #endif
  72. { int i;
  73. static cllist xx;
  74. if (!xx.cerr) {
  75. xx.cerr=1;
  76. xx.csta=NULL;
  77. for(i=0;i<MXUNIT;i++)
  78. {
  79. xx.cunit=i;
  80. (void) f_clos(&xx);
  81. }
  82. }
  83. }
  84. int
  85. #ifdef KR_headers
  86. flush_()
  87. #else
  88. flush_(void)
  89. #endif
  90. { int i;
  91. for(i=0;i<MXUNIT;i++)
  92. if(f__units[i].ufd != NULL && f__units[i].uwrt)
  93. fflush(f__units[i].ufd);
  94. return 0;
  95. }
  96. #ifdef __cplusplus
  97. }
  98. #endif