]> gcc.gnu.org Git - gcc.git/blame - libgfortran/io/rewind.c
error.c (generate_error): Set both iostat and library_return.
[gcc.git] / libgfortran / io / rewind.c
CommitLineData
6de9cd9a
DN
1
2/* Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
4
5This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7Libgfortran is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12Libgfortran is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with Libgfortran; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22#include "config.h"
23#include "libgfortran.h"
24#include "io.h"
25
26/* rewind.c-- Implement the rewind statement */
27
28void
29st_rewind (void)
30{
909087e0 31 gfc_unit *u;
6de9cd9a
DN
32
33 library_start ();
34
35 u = find_unit (ioparm.unit);
36 if (u != NULL)
37 {
38 if (u->flags.access != ACCESS_SEQUENTIAL)
39 generate_error (ERROR_BAD_OPTION,
40 "Cannot REWIND a file opened for DIRECT access");
41 else
42 {
c100eff1 43 /* If we have been writing to the file, the last written record
e041cc5a 44 is the last record in the file, so truncate the file now.
c100eff1
PB
45 Reset to read mode so two consecutive rewind statements
46 don't delete the file contents. */
55948b69 47 if (u->mode==WRITING)
6de9cd9a 48 struncate(u->s);
c100eff1 49 u->mode = READING;
6de9cd9a
DN
50 u->last_record = 0;
51 if (sseek (u->s, 0) == FAILURE)
52 generate_error (ERROR_OS, NULL);
53
54 u->endfile = NO_ENDFILE;
55 u->current_record = 0;
56 test_endfile (u);
57 }
58 }
59
60 library_end ();
61}
This page took 0.07947 seconds and 5 git commands to generate.