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 Implements Fortran WAIT statement.
22  */
23 
24 #include "global.h"
25 #include "async.h"
26 
27 #ifdef WIN32
28 #define access _access
29 #endif
30 
31 /* ------------------------------------------------------------------ */
32 
33 __INT_T
34 ENTF90IO(WAIT, wait)(unit, bitv, iostat, id) __INT_T *unit; /* unit number */
35 __INT_T *bitv;
36 __INT_T *iostat;
37 __INT_T *id;
38 {
39   FIO_FCB *f;
40   int i;
41   int s = 0;
42 
43   __fort_status_init(bitv, iostat);
44   __fortio_errinit03(*unit, *bitv, iostat, "WAIT");
45   if (ILLEGAL_UNIT(*unit)) {
46     s = __fortio_error(FIO_EUNIT);
47     __fortio_errend03();
48     return s;
49   }
50 
51   f = __fortio_find_unit(*unit);
52   if (f == NULL) {
53     __fortio_errend03();
54     return (0);
55   }
56 
57   /* check for outstanding async i/o */
58 
59   if (f->asy_rw) {/* stop any async i/o */
60     f->asy_rw = 0;
61     if (Fio_asy_disable(f->asyptr) == -1) {
62       s = (__fortio_error(__io_errno()));
63       __fortio_errend03();
64       return s;
65     }
66   }
67 
68   __fortio_errend03();
69   return 0; /* no error occurred */
70 }
71