OSDN Git Service

* intrinsics/c99_functions.c, intrinsics/eoshift0.c,
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / flush.c
1 /* Implementation of the FLUSH intrinsic.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3    Contributed by Steven G. Kargl <kargls@comcast.net>.
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB.  If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #include "config.h"
24 #include "libgfortran.h"
25
26 #ifdef HAVE_STDLIB_H
27 #include <stdlib.h>
28 #endif
29
30 #include "../io/io.h"
31
32 /* SUBROUTINE FLUSH(UNIT)
33    INTEGER, INTENT(IN), OPTIONAL :: UNIT  */
34
35 static void
36 recursive_flush (gfc_unit *us)
37 {
38   /* There can be no open files.  */
39   if (us == NULL)
40     return;
41
42   flush (us->s);
43   recursive_flush (us->left);
44   recursive_flush (us->right);
45 }
46
47
48 void
49 prefix(flush_i4) (GFC_INTEGER_4 * unit)
50 {
51   gfc_unit *us;
52
53   /* flush all streams */
54   if (unit == NULL)
55     {
56       us = g.unit_root;
57       recursive_flush(us);
58     }
59   else
60     {
61       us = find_unit(*unit);
62       if (us != NULL)
63         flush (us->s);
64     }
65 }