annotate libgfortran/io/close.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 /* Copyright (C) 2002-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2 Contributed by Andy Vaught
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 Libgfortran is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 Libgfortran is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "io.h"
kono
parents:
diff changeset
26 #include "unix.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
27 #include "async.h"
111
kono
parents:
diff changeset
28 #include <limits.h>
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
29 #if !HAVE_UNLINK_OPEN_FILE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
30 #include <string.h>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
31 #endif
111
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 typedef enum
kono
parents:
diff changeset
34 { CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
kono
parents:
diff changeset
35 close_status;
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 static const st_option status_opt[] = {
kono
parents:
diff changeset
38 {"keep", CLOSE_KEEP},
kono
parents:
diff changeset
39 {"delete", CLOSE_DELETE},
kono
parents:
diff changeset
40 {NULL, 0}
kono
parents:
diff changeset
41 };
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 extern void st_close (st_parameter_close *);
kono
parents:
diff changeset
45 export_proto(st_close);
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 void
kono
parents:
diff changeset
48 st_close (st_parameter_close *clp)
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 close_status status;
kono
parents:
diff changeset
51 gfc_unit *u;
kono
parents:
diff changeset
52 #if !HAVE_UNLINK_OPEN_FILE
kono
parents:
diff changeset
53 char *path;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 path = NULL;
kono
parents:
diff changeset
56 #endif
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 library_start (&clp->common);
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED :
kono
parents:
diff changeset
61 find_option (&clp->common, clp->status, clp->status_len,
kono
parents:
diff changeset
62 status_opt, "Bad STATUS parameter in CLOSE statement");
kono
parents:
diff changeset
63
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64 u = find_unit (clp->common.unit);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66 if (ASYNC_IO && u && u->au)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
67 if (async_wait (&(clp->common), u->au))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 library_end ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 return;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
72
111
kono
parents:
diff changeset
73 if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK)
kono
parents:
diff changeset
74 {
kono
parents:
diff changeset
75 library_end ();
kono
parents:
diff changeset
76 return;
kono
parents:
diff changeset
77 }
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 if (u != NULL)
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 if (close_share (u) < 0)
kono
parents:
diff changeset
82 generate_error (&clp->common, LIBERROR_OS, "Problem in CLOSE");
kono
parents:
diff changeset
83 if (u->flags.status == STATUS_SCRATCH)
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 if (status == CLOSE_KEEP)
kono
parents:
diff changeset
86 generate_error (&clp->common, LIBERROR_BAD_OPTION,
kono
parents:
diff changeset
87 "Can't KEEP a scratch file on CLOSE");
kono
parents:
diff changeset
88 #if !HAVE_UNLINK_OPEN_FILE
kono
parents:
diff changeset
89 path = strdup (u->filename);
kono
parents:
diff changeset
90 #endif
kono
parents:
diff changeset
91 }
kono
parents:
diff changeset
92 else
kono
parents:
diff changeset
93 {
kono
parents:
diff changeset
94 if (status == CLOSE_DELETE)
kono
parents:
diff changeset
95 {
kono
parents:
diff changeset
96 if (u->flags.readonly)
kono
parents:
diff changeset
97 generate_warning (&clp->common, "STATUS set to DELETE on CLOSE"
kono
parents:
diff changeset
98 " but file protected by READONLY specifier");
kono
parents:
diff changeset
99 else
kono
parents:
diff changeset
100 {
kono
parents:
diff changeset
101 #if HAVE_UNLINK_OPEN_FILE
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
102
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
103 if (remove (u->filename))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
104 generate_error (&clp->common, LIBERROR_OS,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
105 "File cannot be deleted");
111
kono
parents:
diff changeset
106 #else
kono
parents:
diff changeset
107 path = strdup (u->filename);
kono
parents:
diff changeset
108 #endif
kono
parents:
diff changeset
109 }
kono
parents:
diff changeset
110 }
kono
parents:
diff changeset
111 }
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 close_unit (u);
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 #if !HAVE_UNLINK_OPEN_FILE
kono
parents:
diff changeset
116 if (path != NULL)
kono
parents:
diff changeset
117 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
118 if (remove (path))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
119 generate_error (&clp->common, LIBERROR_OS,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
120 "File cannot be deleted");
111
kono
parents:
diff changeset
121 free (path);
kono
parents:
diff changeset
122 }
kono
parents:
diff changeset
123 #endif
kono
parents:
diff changeset
124 }
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */
kono
parents:
diff changeset
127 library_end ();
kono
parents:
diff changeset
128 }