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