]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/io/close.c
chdir.c, [...]: Include <string.h> for prototypes.
[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
57dea9f6
TM
11In addition to the permissions in the GNU General Public License, the
12Free Software Foundation gives you unlimited permission to link the
13compiled version of this file into combinations with other programs,
14and to distribute those combinations without any restriction coming
15from the use of this file. (The General Public License restrictions
16do apply in other respects; for example, they cover modification of
17the file, and distribution when not linked into a combine
18executable.)
19
6de9cd9a
DN
20Libgfortran is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with Libgfortran; see the file COPYING. If not, write to
27the Free Software Foundation, 59 Temple Place - Suite 330,
28Boston, MA 02111-1307, USA. */
29
30#include "config.h"
31#include "libgfortran.h"
32#include "io.h"
33
34typedef enum
35{ CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
36close_status;
37
38static st_option status_opt[] = {
39 {"keep", CLOSE_KEEP},
40 {"delete", CLOSE_DELETE},
41 {NULL}
42};
43
44
7d7b8bfe
RH
45extern void st_close (void);
46export_proto(st_close);
47
6de9cd9a
DN
48void
49st_close (void)
50{
51 close_status status;
909087e0 52 gfc_unit *u;
6de9cd9a
DN
53
54 library_start ();
55
56 status = (ioparm.status == NULL) ? CLOSE_UNSPECIFIED :
57 find_option (ioparm.status, ioparm.status_len, status_opt,
58 "Bad STATUS parameter in CLOSE statement");
59
60 if (ioparm.library_return != LIBRARY_OK)
61 return;
62
63 u = find_unit (ioparm.unit);
64 if (u != NULL)
65 {
66 if (u->flags.status == STATUS_SCRATCH)
67 {
68 if (status == CLOSE_KEEP)
69 generate_error (ERROR_BAD_OPTION,
70 "Can't KEEP a scratch file on CLOSE");
71 }
72 else
73 {
74 if (status == CLOSE_DELETE)
75 delete_file (u);
76 }
77
78 close_unit (u);
79 }
80
81 library_end ();
82}