acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
[gcc.git] / libgfortran / io / close.c
1 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
2 Contributed by Andy Vaught
3
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
5
6 Libgfortran is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Libgfortran; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "config.h"
22 #include "libgfortran.h"
23 #include "io.h"
24
25 typedef enum
26 { CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
27 close_status;
28
29 static st_option status_opt[] = {
30 {"keep", CLOSE_KEEP},
31 {"delete", CLOSE_DELETE},
32 {NULL}
33 };
34
35
36 extern void st_close (void);
37 export_proto(st_close);
38
39 void
40 st_close (void)
41 {
42 close_status status;
43 gfc_unit *u;
44
45 library_start ();
46
47 status = (ioparm.status == NULL) ? CLOSE_UNSPECIFIED :
48 find_option (ioparm.status, ioparm.status_len, status_opt,
49 "Bad STATUS parameter in CLOSE statement");
50
51 if (ioparm.library_return != LIBRARY_OK)
52 return;
53
54 u = find_unit (ioparm.unit);
55 if (u != NULL)
56 {
57 if (u->flags.status == STATUS_SCRATCH)
58 {
59 if (status == CLOSE_KEEP)
60 generate_error (ERROR_BAD_OPTION,
61 "Can't KEEP a scratch file on CLOSE");
62 }
63 else
64 {
65 if (status == CLOSE_DELETE)
66 delete_file (u);
67 }
68
69 close_unit (u);
70 }
71
72 library_end ();
73 }