]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/io/rewind.c
re PR libfortran/19280 (Inconsistent licensing of libgfortran)
[thirdparty/gcc.git] / libgfortran / io / rewind.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
34/* rewind.c-- Implement the rewind statement */
35
7d7b8bfe
RH
36extern void st_rewind (void);
37export_proto(st_rewind);
38
6de9cd9a
DN
39void
40st_rewind (void)
41{
909087e0 42 gfc_unit *u;
6de9cd9a
DN
43
44 library_start ();
45
46 u = find_unit (ioparm.unit);
47 if (u != NULL)
48 {
49 if (u->flags.access != ACCESS_SEQUENTIAL)
50 generate_error (ERROR_BAD_OPTION,
51 "Cannot REWIND a file opened for DIRECT access");
52 else
53 {
c100eff1 54 /* If we have been writing to the file, the last written record
e041cc5a 55 is the last record in the file, so truncate the file now.
c100eff1
PB
56 Reset to read mode so two consecutive rewind statements
57 don't delete the file contents. */
55948b69 58 if (u->mode==WRITING)
6de9cd9a 59 struncate(u->s);
c100eff1 60 u->mode = READING;
6de9cd9a
DN
61 u->last_record = 0;
62 if (sseek (u->s, 0) == FAILURE)
63 generate_error (ERROR_OS, NULL);
64
65 u->endfile = NO_ENDFILE;
66 u->current_record = 0;
67 test_endfile (u);
68 }
69 }
70
71 library_end ();
72}