]>
Commit | Line | Data |
---|---|---|
36ae8a61 | 1 | /* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc. |
6de9cd9a DN |
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 | ||
57dea9f6 TM |
11 | In addition to the permissions in the GNU General Public License, the |
12 | Free Software Foundation gives you unlimited permission to link the | |
13 | compiled version of this file into combinations with other programs, | |
14 | and to distribute those combinations without any restriction coming | |
15 | from the use of this file. (The General Public License restrictions | |
16 | do apply in other respects; for example, they cover modification of | |
17 | the file, and distribution when not linked into a combine | |
18 | executable.) | |
19 | ||
6de9cd9a DN |
20 | Libgfortran is distributed in the hope that it will be useful, |
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | GNU General Public License for more details. | |
24 | ||
25 | You should have received a copy of the GNU General Public License | |
26 | along with Libgfortran; see the file COPYING. If not, write to | |
fe2ae685 KC |
27 | the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
28 | Boston, MA 02110-1301, USA. */ | |
6de9cd9a | 29 | |
6de9cd9a | 30 | #include "io.h" |
10c682a0 | 31 | #include <limits.h> |
6de9cd9a DN |
32 | |
33 | typedef enum | |
34 | { CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED } | |
35 | close_status; | |
36 | ||
09003779 | 37 | static const st_option status_opt[] = { |
6de9cd9a DN |
38 | {"keep", CLOSE_KEEP}, |
39 | {"delete", CLOSE_DELETE}, | |
4b6903ec | 40 | {NULL, 0} |
6de9cd9a DN |
41 | }; |
42 | ||
43 | ||
5e805e44 | 44 | extern void st_close (st_parameter_close *); |
7d7b8bfe RH |
45 | export_proto(st_close); |
46 | ||
6de9cd9a | 47 | void |
5e805e44 | 48 | st_close (st_parameter_close *clp) |
6de9cd9a DN |
49 | { |
50 | close_status status; | |
909087e0 | 51 | gfc_unit *u; |
10c682a0 FXC |
52 | #if !HAVE_UNLINK_OPEN_FILE |
53 | char * path; | |
54 | ||
55 | path = NULL; | |
56 | #endif | |
6de9cd9a | 57 | |
5e805e44 | 58 | library_start (&clp->common); |
6de9cd9a | 59 | |
5e805e44 JJ |
60 | status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED : |
61 | find_option (&clp->common, clp->status, clp->status_len, | |
62 | status_opt, "Bad STATUS parameter in CLOSE statement"); | |
6de9cd9a | 63 | |
5e805e44 | 64 | if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK) |
e0fd73d4 FXC |
65 | { |
66 | library_end (); | |
6de9cd9a | 67 | return; |
e0fd73d4 | 68 | } |
6de9cd9a | 69 | |
5e805e44 | 70 | u = find_unit (clp->common.unit); |
6de9cd9a DN |
71 | if (u != NULL) |
72 | { | |
73 | if (u->flags.status == STATUS_SCRATCH) | |
74 | { | |
75 | if (status == CLOSE_KEEP) | |
d74b97cc | 76 | generate_error (&clp->common, LIBERROR_BAD_OPTION, |
6de9cd9a | 77 | "Can't KEEP a scratch file on CLOSE"); |
10c682a0 FXC |
78 | #if !HAVE_UNLINK_OPEN_FILE |
79 | path = (char *) gfc_alloca (u->file_len + 1); | |
80 | unpack_filename (path, u->file, u->file_len); | |
81 | #endif | |
6de9cd9a DN |
82 | } |
83 | else | |
84 | { | |
85 | if (status == CLOSE_DELETE) | |
10c682a0 FXC |
86 | { |
87 | #if HAVE_UNLINK_OPEN_FILE | |
88 | delete_file (u); | |
89 | #else | |
90 | path = (char *) gfc_alloca (u->file_len + 1); | |
91 | unpack_filename (path, u->file, u->file_len); | |
92 | #endif | |
93 | } | |
6de9cd9a DN |
94 | } |
95 | ||
96 | close_unit (u); | |
10c682a0 FXC |
97 | |
98 | #if !HAVE_UNLINK_OPEN_FILE | |
99 | if (path != NULL) | |
100 | unlink (path); | |
101 | #endif | |
6de9cd9a | 102 | } |
b8d403b4 JD |
103 | |
104 | /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */ | |
6de9cd9a DN |
105 | library_end (); |
106 | } |