]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | .. index:: FSEEK, file operation, seek, file operation, position | |
7 | ||
8 | .. _fseek: | |
9 | ||
10 | FSEEK --- Low level file positioning subroutine | |
11 | *********************************************** | |
12 | ||
13 | .. function:: FSEEK(UNIT, OFFSET, WHENCE, STATUS) | |
14 | ||
15 | Moves :samp:`{UNIT}` to the specified :samp:`{OFFSET}`. If :samp:`{WHENCE}` | |
16 | is set to 0, the :samp:`{OFFSET}` is taken as an absolute value ``SEEK_SET``, | |
17 | if set to 1, :samp:`{OFFSET}` is taken to be relative to the current position | |
18 | ``SEEK_CUR``, and if set to 2 relative to the end of the file ``SEEK_END``. | |
19 | On error, :samp:`{STATUS}` is set to a nonzero value. If :samp:`{STATUS}` the seek | |
20 | fails silently. | |
21 | ||
22 | :param UNIT: | |
23 | Shall be a scalar of type ``INTEGER``. | |
24 | ||
25 | :param OFFSET: | |
26 | Shall be a scalar of type ``INTEGER``. | |
27 | ||
28 | :param WHENCE: | |
29 | Shall be a scalar of type ``INTEGER``. | |
30 | Its value shall be either 0, 1 or 2. | |
31 | ||
32 | :param STATUS: | |
33 | (Optional) shall be a scalar of type | |
34 | ``INTEGER(4)``. | |
35 | ||
36 | Standard: | |
37 | GNU extension | |
38 | ||
39 | Class: | |
40 | Subroutine | |
41 | ||
42 | Syntax: | |
43 | .. code-block:: fortran | |
44 | ||
45 | CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS]) | |
46 | ||
47 | Example: | |
48 | .. code-block:: fortran | |
49 | ||
50 | PROGRAM test_fseek | |
51 | INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2 | |
52 | INTEGER :: fd, offset, ierr | |
53 | ||
54 | ierr = 0 | |
55 | offset = 5 | |
56 | fd = 10 | |
57 | ||
58 | OPEN(UNIT=fd, FILE="fseek.test") | |
59 | CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET | |
60 | print *, FTELL(fd), ierr | |
61 | ||
62 | CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end | |
63 | print *, FTELL(fd), ierr | |
64 | ||
65 | CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning | |
66 | print *, FTELL(fd), ierr | |
67 | ||
68 | CLOSE(UNIT=fd) | |
69 | END PROGRAM | |
70 | ||
71 | See also: | |
3ed1b4ce | 72 | :ref:`FTELL` |