]>
Commit | Line | Data |
---|---|---|
6de9cd9a DN |
1 | /* Copyright (C) 2002-2003 Free Software Foundation, Inc. |
2 | Contributed by Andy Vaught | |
3 | ||
4 | This file is part of the GNU Fortran 95 runtime library (libgfortran). | |
5 | ||
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) | |
9 | any later version. | |
10 | ||
57dea9f6 TM |
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 | |
18 | executable.) | |
19 | ||
6de9cd9a DN |
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. | |
24 | ||
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. */ | |
29 | ||
30 | #include "config.h" | |
31 | #include "libgfortran.h" | |
32 | #include "io.h" | |
33 | ||
34 | /* rewind.c-- Implement the rewind statement */ | |
35 | ||
7d7b8bfe RH |
36 | extern void st_rewind (void); |
37 | export_proto(st_rewind); | |
38 | ||
6de9cd9a DN |
39 | void |
40 | st_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 | } |