1 /*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 /* clang-format off */
19
20 /** \file
21 * \brief
22 * Implement Fortran ENDFILE statement.
23 */
24
25 #include "global.h"
26
27 static int
_f90io_endfile(__INT_T * unit,__INT_T * bitv,__INT_T * iostat)28 _f90io_endfile(__INT_T *unit, __INT_T *bitv, __INT_T *iostat)
29 {
30 FIO_FCB *f;
31
32 __fortio_errinit03(*unit, *bitv, iostat, "ENDFILE");
33 if (ILLEGAL_UNIT(*unit))
34 return __fortio_error(FIO_EUNIT);
35
36 /* call rwinit to get FCB pointer, do error checking, and truncate
37 file if necessary: */
38
39 f = __fortio_rwinit(*unit, FIO_UNFORMATTED, 0L, 2 /*endfile*/);
40 if (f == NULL)
41 return ERR_FLAG;
42
43 f->eof_flag = TRUE;
44 return 0; /* no error occurred */
45 }
46
47 __INT_T
48 ENTF90IO(ENDFILE, endfile)(unit, bitv, iostat) __INT_T *unit;
49 __INT_T *bitv;
50 __INT_T *iostat;
51 {
52 int s = 0;
53
54 __fort_status_init(bitv, iostat);
55 if (LOCAL_MODE || GET_DIST_LCPU == GET_DIST_IOPROC)
56 s = _f90io_endfile(unit, bitv, iostat);
57 __fortio_errend03();
58 return DIST_STATUS_BCST(s);
59 }
60
61 __INT_T
62 ENTCRF90IO(ENDFILE, endfile)(unit, bitv, iostat) __INT_T *unit;
63 __INT_T *bitv;
64 __INT_T *iostat;
65 {
66 int s = 0;
67 s = _f90io_endfile(unit, bitv, iostat);
68 __fortio_errend03();
69 return s;
70 }
71