2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libf2c / libI77 / close.c
blob769c569f8c51130167c26e93a82c55c3c889ebfb
1 #include "config.h"
2 #include "f2c.h"
3 #include "fio.h"
5 #undef abs
6 #undef min
7 #undef max
8 #include <stdlib.h>
9 #ifdef NON_UNIX_STDIO
10 #ifndef unlink
11 #define unlink remove
12 #endif
13 #else
14 #if defined (MSDOS) && !defined (GO32)
15 #include "io.h"
16 #else
17 extern int unlink (const char *);
18 #endif
19 #endif
21 integer
22 f_clos (cllist * a)
24 unit *b;
26 if (f__init & 2)
27 f__fatal (131, "I/O recursion");
28 if (a->cunit >= MXUNIT)
29 return (0);
30 b = &f__units[a->cunit];
31 if (b->ufd == NULL)
32 goto done;
33 if (b->uscrtch == 1)
34 goto Delete;
35 if (!a->csta)
36 goto Keep;
37 switch (*a->csta)
39 default:
40 Keep:
41 case 'k':
42 case 'K':
43 if (b->uwrt == 1)
44 t_runc ((alist *) a);
45 if (b->ufnm)
47 fclose (b->ufd);
48 free (b->ufnm);
50 break;
51 case 'd':
52 case 'D':
53 Delete:
54 fclose (b->ufd);
55 if (b->ufnm)
57 unlink (b->ufnm);
58 /*SYSDEP*/ free (b->ufnm);
61 b->ufd = NULL;
62 done:
63 b->uend = 0;
64 b->ufnm = NULL;
65 return (0);
68 void
69 f_exit (void)
71 int i;
72 static cllist xx;
73 if (!(f__init & 1))
74 return; /* Not initialized, so no open units. */
75 /* I/O no longer in progress. If, during an I/O operation (such
76 as waiting for the user to enter a line), there is an
77 interrupt (such as ^C to stop the program on a UNIX system),
78 f_exit() is called, but there is no longer any I/O in
79 progress. Without turning off this flag, f_clos() would
80 think that there is an I/O recursion in this circumstance. */
81 f__init &= ~2;
82 if (!xx.cerr)
84 xx.cerr = 1;
85 xx.csta = NULL;
86 for (i = 0; i < MXUNIT; i++)
88 xx.cunit = i;
89 (void) f_clos (&xx);
93 int
94 G77_flush_0 (void)
96 int i;
97 for (i = 0; i < MXUNIT; i++)
98 if (f__units[i].ufd != NULL && f__units[i].uwrt)
99 fflush (f__units[i].ufd);
100 return 0;