2004-08-27 Bud Davis <bdavis9659@comcast.net>
[official-gcc.git] / libgfortran / io / rewind.c
blobd9758a6d5ec8c6b4921ee0b77c0c3d3ab646d215
2 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
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 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Libgfortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "libgfortran.h"
24 #include "io.h"
26 /* rewind.c-- Implement the rewind statement */
28 void
29 st_rewind (void)
31 gfc_unit *u;
33 library_start ();
35 u = find_unit (ioparm.unit);
36 if (u != NULL)
38 if (u->flags.access != ACCESS_SEQUENTIAL)
39 generate_error (ERROR_BAD_OPTION,
40 "Cannot REWIND a file opened for DIRECT access");
41 else
43 if (u->mode==WRITING)
44 struncate(u->s);
45 u->last_record = 0;
46 if (sseek (u->s, 0) == FAILURE)
47 generate_error (ERROR_OS, NULL);
49 u->endfile = NO_ENDFILE;
50 u->current_record = 0;
51 test_endfile (u);
55 library_end ();