GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 16 / 0 / 16
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 12 / 0 / 12

fx_file_extended_relative_seek.c
Line Branch Exec Source
1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2026-present Eclipse ThreadX contributors
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** FileX Component */
17 /** */
18 /** File */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define FX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "fx_api.h"
29 #include "fx_system.h"
30 #include "fx_directory.h"
31 #include "fx_file.h"
32 #include "fx_utility.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _fx_file_extended_relative_seek PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function positions the internal file pointers to the specified */
48 /* byte relative offset such that the next read or write operation is */
49 /* performed there. */
50 /* */
51 /* INPUT */
52 /* */
53 /* file_ptr File control block pointer */
54 /* byte_offset Byte offset of the seek */
55 /* seek_from Direction for relative seek, */
56 /* legal values are: */
57 /* */
58 /* FX_SEEK_BEGIN */
59 /* FX_SEEK_END */
60 /* FX_SEEK_FORWARD */
61 /* FX_SEEK_BACK */
62 /* */
63 /* OUTPUT */
64 /* */
65 /* return status */
66 /* */
67 /* CALLS */
68 /* */
69 /* _fx_file_extended_seek Seek to specified position */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Application Code */
74 /* */
75 /**************************************************************************/
76 3201880 UINT _fx_file_extended_relative_seek(FX_FILE *file_ptr, ULONG64 byte_offset, UINT seek_from)
77 {
78
79 #ifndef FX_MEDIA_STATISTICS_DISABLE
80 FX_MEDIA *media_ptr;
81
82 /* First, determine if the file is still open. */
83
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 3201871 times.
3201880 if (file_ptr -> fx_file_id != FX_FILE_ID)
84 {
85
86 /* Return the file not open error status. */
87 9 return(FX_NOT_OPEN);
88 }
89
90 /* Setup pointer to media structure. */
91 3201871 media_ptr = file_ptr -> fx_file_media_ptr;
92
93 /* Increment the number of times this service has been called. */
94 3201871 media_ptr -> fx_media_file_relative_seeks++;
95 #endif
96
97 /* If trace is enabled, insert this event into the trace buffer. */
98 FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_RELATIVE_SEEK, file_ptr, byte_offset, seek_from, file_ptr -> fx_file_current_file_offset, FX_TRACE_FILE_EVENTS, 0, 0)
99
100 /* Determine if seeking from the beginning is requested. */
101
2/2
✓ Branch 4 → 5 taken 3200042 times.
✓ Branch 4 → 7 taken 1829 times.
3201871 if (seek_from == FX_SEEK_BEGIN)
102 {
103
104 /* Yes, use the base file seek routine to seek from the beginning of
105 the file. */
106 3200042 return(_fx_file_extended_seek(file_ptr, byte_offset));
107 }
108 /* Otherwise, determine if seeking from the end is requested. */
109
2/2
✓ Branch 7 → 8 taken 455 times.
✓ Branch 7 → 13 taken 1374 times.
1829 else if (seek_from == FX_SEEK_END)
110 {
111
112 /* Yes, seek from the end of the file. */
113
114 /* Determine if the requested seek offset is greater than
115 the file size. */
116
2/2
✓ Branch 8 → 9 taken 9 times.
✓ Branch 8 → 11 taken 446 times.
455 if (byte_offset >= file_ptr -> fx_file_current_file_size)
117 {
118
119 /* Yes, just seek to the beginning of the file. */
120 9 return(_fx_file_extended_seek(file_ptr, ((ULONG64) 0)));
121 }
122 else
123 {
124
125 /* Logically seek from the end of the file. */
126 446 return(_fx_file_extended_seek(file_ptr, file_ptr -> fx_file_current_file_size - byte_offset));
127 }
128 }
129 /* Otherwise, determine if seeking from the current position is requested. */
130
2/2
✓ Branch 13 → 14 taken 891 times.
✓ Branch 13 → 16 taken 483 times.
1374 else if (seek_from == FX_SEEK_FORWARD)
131 {
132
133 /* Yes, just seek ahead from the current file position. */
134 891 return(_fx_file_extended_seek(file_ptr, file_ptr -> fx_file_current_file_offset + byte_offset));
135 }
136 /* Otherwise, seeking backward from the current position is assumed. */
137 else
138 {
139
140 /* Determine if the backward offset is greater than the current file offset. */
141
2/2
✓ Branch 16 → 17 taken 9 times.
✓ Branch 16 → 19 taken 474 times.
483 if (byte_offset >= file_ptr -> fx_file_current_file_offset)
142 {
143
144 /* Yes, just position the file to the beginning. */
145 9 return(_fx_file_extended_seek(file_ptr, ((ULONG64) 0)));
146 }
147 else
148 {
149
150 /* Seek backward relative to the current position. */
151 474 return(_fx_file_extended_seek(file_ptr, file_ptr -> fx_file_current_file_offset - byte_offset));
152 }
153 }
154 }
155
156