1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** FileX Component                                                       */
16 /**                                                                       */
17 /**   File                                                                */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define FX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "fx_api.h"
28 #include "fx_file.h"
29 
30 FX_CALLER_CHECKING_EXTERNS
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _fxe_file_extended_relative_seek                    PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the file relative seek call.     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    file_ptr                              File control block pointer    */
50 /*    byte_offset                           Byte offset of the seek       */
51 /*    seek_from                             Direction for relative seek,  */
52 /*                                          legal values are:             */
53 /*                                                                        */
54 /*                                              FX_SEEK_BEGIN             */
55 /*                                              FX_SEEK_END               */
56 /*                                              FX_SEEK_FORWARD           */
57 /*                                              FX_SEEK_BACK              */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    return status                                                       */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    _fx_file_extended_relative_seek       Actual relative file seek     */
66 /*                                            service                     */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
77 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*                                                                        */
80 /**************************************************************************/
_fxe_file_extended_relative_seek(FX_FILE * file_ptr,ULONG64 byte_offset,UINT seek_from)81 UINT  _fxe_file_extended_relative_seek(FX_FILE *file_ptr, ULONG64 byte_offset, UINT seek_from)
82 {
83 
84 UINT status;
85 
86 
87     /* Check for a null file pointer.  */
88     if (file_ptr == FX_NULL)
89     {
90         return(FX_PTR_ERROR);
91     }
92 
93     /* Check for valid seek from option.  */
94     if ((seek_from != FX_SEEK_BEGIN) && (seek_from != FX_SEEK_END) &&
95         (seek_from != FX_SEEK_FORWARD) && (seek_from != FX_SEEK_BACK))
96     {
97         return(FX_INVALID_OPTION);
98     }
99 
100     /* Check for a valid caller.  */
101     FX_CALLER_CHECKING_CODE
102 
103     /* Call actual file relative seek service.  */
104     status =  _fx_file_extended_relative_seek(file_ptr, byte_offset, seek_from);
105 
106     /* Seek is complete, return status.  */
107     return(status);
108 }
109 
110