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 LIB3F 64-bit fseek subroutine.  */
22 
23 /* must include ent3f.h AFTER io3f.h */
24 #include "io3f.h"
25 #include "ent3f.h"
26 
27 extern FILE *__getfile3f();
28 
29 int ENT3F(FSEEK64, fseek64)(lu, offset, from) int *lu;
30 long long *offset;
31 int *from;
32 {
33   FILE *f;
34 
35   /* DON'T issue any error messages */
36 
37   f = __getfile3f(*lu);
38   if (f) {
39     int fr;
40 
41     switch (*from) {
42     case 0:
43       fr = SEEK_SET;
44       break;
45     case 1:
46       fr = SEEK_CUR;
47       break;
48     case 2:
49       fr = SEEK_END;
50       break;
51     default:
52       /* ERROR */
53       fprintf(__io_stderr(), "Illegal fseek value %d\n", *from);
54       return 0;
55     }
56     if (__io_fseek64(f, *offset, fr) == 0)
57       return 0;
58     return __io_errno();
59   }
60 
61   return 0;
62 }
63