1 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
2 Contributed by Andy Vaught
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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)
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
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.
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, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
31 #include "libgfortran.h"
34 /* rewind.c-- Implement the rewind statement */
36 extern void st_rewind (void);
37 export_proto(st_rewind
);
46 u
= find_unit (ioparm
.unit
);
49 if (u
->flags
.access
!= ACCESS_SEQUENTIAL
)
50 generate_error (ERROR_BAD_OPTION
,
51 "Cannot REWIND a file opened for DIRECT access");
54 /* If we have been writing to the file, the last written record
55 is the last record in the file, so truncate the file now.
56 Reset to read mode so two consecutive rewind statements
57 don't delete the file contents. */
62 if (sseek (u
->s
, 0) == FAILURE
)
63 generate_error (ERROR_OS
, NULL
);
65 u
->endfile
= NO_ENDFILE
;
66 u
->current_record
= 0;
69 /* update position for INQUIRE */
70 u
->flags
.position
= POSITION_REWIND
;