]>
Commit | Line | Data |
---|---|---|
748086b7 | 1 | /* Copyright (C) 2002, 2003, 2005, 2007, 2009 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 | |
748086b7 | 8 | the Free Software Foundation; either version 3, or (at your option) |
6de9cd9a DN |
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 | ||
748086b7 JJ |
16 | Under Section 7 of GPL version 3, you are granted additional |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a | 24 | |
6de9cd9a | 25 | #include "io.h" |
10c682a0 | 26 | #include <limits.h> |
6de9cd9a DN |
27 | |
28 | typedef enum | |
29 | { CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED } | |
30 | close_status; | |
31 | ||
09003779 | 32 | static const st_option status_opt[] = { |
6de9cd9a DN |
33 | {"keep", CLOSE_KEEP}, |
34 | {"delete", CLOSE_DELETE}, | |
4b6903ec | 35 | {NULL, 0} |
6de9cd9a DN |
36 | }; |
37 | ||
38 | ||
5e805e44 | 39 | extern void st_close (st_parameter_close *); |
7d7b8bfe RH |
40 | export_proto(st_close); |
41 | ||
6de9cd9a | 42 | void |
5e805e44 | 43 | st_close (st_parameter_close *clp) |
6de9cd9a DN |
44 | { |
45 | close_status status; | |
909087e0 | 46 | gfc_unit *u; |
10c682a0 FXC |
47 | #if !HAVE_UNLINK_OPEN_FILE |
48 | char * path; | |
49 | ||
50 | path = NULL; | |
51 | #endif | |
6de9cd9a | 52 | |
5e805e44 | 53 | library_start (&clp->common); |
6de9cd9a | 54 | |
5e805e44 JJ |
55 | status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED : |
56 | find_option (&clp->common, clp->status, clp->status_len, | |
57 | status_opt, "Bad STATUS parameter in CLOSE statement"); | |
6de9cd9a | 58 | |
5e805e44 | 59 | if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK) |
e0fd73d4 FXC |
60 | { |
61 | library_end (); | |
6de9cd9a | 62 | return; |
e0fd73d4 | 63 | } |
6de9cd9a | 64 | |
5e805e44 | 65 | u = find_unit (clp->common.unit); |
6de9cd9a DN |
66 | if (u != NULL) |
67 | { | |
68 | if (u->flags.status == STATUS_SCRATCH) | |
69 | { | |
70 | if (status == CLOSE_KEEP) | |
d74b97cc | 71 | generate_error (&clp->common, LIBERROR_BAD_OPTION, |
6de9cd9a | 72 | "Can't KEEP a scratch file on CLOSE"); |
10c682a0 FXC |
73 | #if !HAVE_UNLINK_OPEN_FILE |
74 | path = (char *) gfc_alloca (u->file_len + 1); | |
75 | unpack_filename (path, u->file, u->file_len); | |
76 | #endif | |
6de9cd9a DN |
77 | } |
78 | else | |
79 | { | |
80 | if (status == CLOSE_DELETE) | |
10c682a0 FXC |
81 | { |
82 | #if HAVE_UNLINK_OPEN_FILE | |
83 | delete_file (u); | |
84 | #else | |
85 | path = (char *) gfc_alloca (u->file_len + 1); | |
86 | unpack_filename (path, u->file, u->file_len); | |
87 | #endif | |
88 | } | |
6de9cd9a DN |
89 | } |
90 | ||
91 | close_unit (u); | |
10c682a0 FXC |
92 | |
93 | #if !HAVE_UNLINK_OPEN_FILE | |
94 | if (path != NULL) | |
95 | unlink (path); | |
96 | #endif | |
6de9cd9a | 97 | } |
b8d403b4 JD |
98 | |
99 | /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */ | |
6de9cd9a DN |
100 | library_end (); |
101 | } |