OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libgfortran/] [io/] [close.c] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
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
 
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
 
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
27
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
28
Boston, MA 02110-1301, USA.  */
29
 
30
#include "config.h"
31
#include "libgfortran.h"
32
#include "io.h"
33
#include <limits.h>
34
 
35
typedef enum
36
{ CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
37
close_status;
38
 
39
static const st_option status_opt[] = {
40
  {"keep", CLOSE_KEEP},
41
  {"delete", CLOSE_DELETE},
42
  {NULL, 0}
43
};
44
 
45
 
46
extern void st_close (st_parameter_close *);
47
export_proto(st_close);
48
 
49
void
50
st_close (st_parameter_close *clp)
51
{
52
  close_status status;
53
  gfc_unit *u;
54
#if !HAVE_UNLINK_OPEN_FILE
55
  char * path;
56
 
57
  path = NULL;
58
#endif
59
 
60
  library_start (&clp->common);
61
 
62
  status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED :
63
    find_option (&clp->common, clp->status, clp->status_len,
64
                 status_opt, "Bad STATUS parameter in CLOSE statement");
65
 
66
  if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK)
67
  {
68
    library_end ();
69
    return;
70
  }
71
 
72
  u = find_unit (clp->common.unit);
73
  if (u != NULL)
74
    {
75
      if (u->flags.status == STATUS_SCRATCH)
76
        {
77
          if (status == CLOSE_KEEP)
78
            generate_error (&clp->common, ERROR_BAD_OPTION,
79
                            "Can't KEEP a scratch file on CLOSE");
80
#if !HAVE_UNLINK_OPEN_FILE
81
          path = (char *) gfc_alloca (u->file_len + 1);
82
          unpack_filename (path, u->file, u->file_len);
83
#endif
84
        }
85
      else
86
        {
87
          if (status == CLOSE_DELETE)
88
            {
89
#if HAVE_UNLINK_OPEN_FILE
90
              delete_file (u);
91
#else
92
              path = (char *) gfc_alloca (u->file_len + 1);
93
              unpack_filename (path, u->file, u->file_len);
94
#endif
95
            }
96
        }
97
 
98
      close_unit (u);
99
 
100
#if !HAVE_UNLINK_OPEN_FILE
101
      if (path != NULL)
102
        unlink (path);
103
#endif
104
    }
105
 
106
  library_end ();
107
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.