GCC Code Coverage Report


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

fxe_file_date_time_set.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_file.h"
30
31
32 FX_CALLER_CHECKING_EXTERNS
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _fxe_file_date_time_set PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function checks for errors in the file date/time set service. */
48 /* */
49 /* INPUT */
50 /* */
51 /* media_ptr Media control block pointer */
52 /* file_name File name pointer */
53 /* year Year */
54 /* month Month */
55 /* day Day */
56 /* hour Hour */
57 /* minute Minute */
58 /* second Second */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* return status */
63 /* */
64 /* CALLS */
65 /* */
66 /* _fx_file_date_time_set Actual file date/time set */
67 /* service */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application Code */
72 /* */
73 /**************************************************************************/
74 2470 UINT _fxe_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name,
75 UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second)
76 {
77
78 UINT status;
79
80
81 /* Check for a NULL media or file name pointer. */
82
4/4
✓ Branch 2 → 3 taken 2462 times.
✓ Branch 2 → 4 taken 8 times.
✓ Branch 3 → 4 taken 8 times.
✓ Branch 3 → 5 taken 2454 times.
2470 if ((media_ptr == FX_NULL) || (file_name == FX_NULL))
83 {
84 16 return(FX_PTR_ERROR);
85 }
86
87 /* Check for invalid year. */
88
4/4
✓ Branch 5 → 6 taken 2446 times.
✓ Branch 5 → 7 taken 8 times.
✓ Branch 6 → 7 taken 8 times.
✓ Branch 6 → 8 taken 2438 times.
2454 if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR))
89 {
90 16 return(FX_INVALID_YEAR);
91 }
92
93 /* Check for invalid day. */
94
2/2
✓ Branch 8 → 9 taken 104 times.
✓ Branch 8 → 10 taken 2334 times.
2438 if (day < 1)
95 {
96 104 return(FX_INVALID_DAY);
97 }
98
99 /* Check for invalid day. */
100
13/13
✓ Branch 10 → 11 taken 56 times.
✓ Branch 10 → 14 taken 32 times.
✓ Branch 10 → 20 taken 16 times.
✓ Branch 10 → 23 taken 16 times.
✓ Branch 10 → 26 taken 16 times.
✓ Branch 10 → 29 taken 16 times.
✓ Branch 10 → 32 taken 16 times.
✓ Branch 10 → 35 taken 16 times.
✓ Branch 10 → 38 taken 16 times.
✓ Branch 10 → 41 taken 16 times.
✓ Branch 10 → 44 taken 16 times.
✓ Branch 10 → 47 taken 2094 times.
✓ Branch 10 → 50 taken 8 times.
2334 switch (month)
101 {
102
103 56 case 1:
104 {
105
106 /* Check for 31 days. */
107
2/2
✓ Branch 11 → 12 taken 8 times.
✓ Branch 11 → 13 taken 48 times.
56 if (day > 31)
108 {
109 8 return(FX_INVALID_DAY);
110 }
111 48 break;
112 }
113
114 32 case 2:
115 {
116
117 /* Check for leap year. */
118
2/2
✓ Branch 14 → 15 taken 16 times.
✓ Branch 14 → 17 taken 16 times.
32 if ((year % 4) == 0)
119 {
120
121 /* Leap year, February has 29 days. */
122
2/2
✓ Branch 15 → 16 taken 8 times.
✓ Branch 15 → 19 taken 8 times.
16 if (day > 29)
123 {
124 8 return(FX_INVALID_DAY);
125 }
126 }
127 else
128 {
129
130 /* Otherwise, non-leap year. February has
131 28 days. */
132
2/2
✓ Branch 17 → 18 taken 8 times.
✓ Branch 17 → 19 taken 8 times.
16 if (day > 28)
133 {
134 8 return(FX_INVALID_DAY);
135 }
136 }
137 16 break;
138 }
139
140 16 case 3:
141 {
142
143 /* Check for 31 days. */
144
2/2
✓ Branch 20 → 21 taken 8 times.
✓ Branch 20 → 22 taken 8 times.
16 if (day > 31)
145 {
146 8 return(FX_INVALID_DAY);
147 }
148 8 break;
149 }
150
151 16 case 4:
152 {
153
154 /* Check for 30 days. */
155
2/2
✓ Branch 23 → 24 taken 8 times.
✓ Branch 23 → 25 taken 8 times.
16 if (day > 30)
156 {
157 8 return(FX_INVALID_DAY);
158 }
159 8 break;
160 }
161
162 16 case 5:
163 {
164
165 /* Check for 31 days. */
166
2/2
✓ Branch 26 → 27 taken 8 times.
✓ Branch 26 → 28 taken 8 times.
16 if (day > 31)
167 {
168 8 return(FX_INVALID_DAY);
169 }
170 8 break;
171 }
172
173 16 case 6:
174 {
175
176 /* Check for 30 days. */
177
2/2
✓ Branch 29 → 30 taken 8 times.
✓ Branch 29 → 31 taken 8 times.
16 if (day > 30)
178 {
179 8 return(FX_INVALID_DAY);
180 }
181 8 break;
182 }
183
184 16 case 7:
185 {
186
187 /* Check for 31 days. */
188
2/2
✓ Branch 32 → 33 taken 8 times.
✓ Branch 32 → 34 taken 8 times.
16 if (day > 31)
189 {
190 8 return(FX_INVALID_DAY);
191 }
192 8 break;
193 }
194
195 16 case 8:
196 {
197
198 /* Check for 31 days. */
199
2/2
✓ Branch 35 → 36 taken 8 times.
✓ Branch 35 → 37 taken 8 times.
16 if (day > 31)
200 {
201 8 return(FX_INVALID_DAY);
202 }
203 8 break;
204 }
205
206 16 case 9:
207 {
208
209 /* Check for 30 days. */
210
2/2
✓ Branch 38 → 39 taken 8 times.
✓ Branch 38 → 40 taken 8 times.
16 if (day > 30)
211 {
212 8 return(FX_INVALID_DAY);
213 }
214 8 break;
215 }
216
217 16 case 10:
218 {
219
220 /* Check for 31 days. */
221
2/2
✓ Branch 41 → 42 taken 8 times.
✓ Branch 41 → 43 taken 8 times.
16 if (day > 31)
222 {
223 8 return(FX_INVALID_DAY);
224 }
225 8 break;
226 }
227
228 16 case 11:
229 {
230
231 /* Check for 30 days. */
232
2/2
✓ Branch 44 → 45 taken 8 times.
✓ Branch 44 → 46 taken 8 times.
16 if (day > 30)
233 {
234 8 return(FX_INVALID_DAY);
235 }
236 8 break;
237 }
238
239 2094 case 12:
240 {
241
242 /* Check for 31 days. */
243
2/2
✓ Branch 47 → 48 taken 8 times.
✓ Branch 47 → 49 taken 2086 times.
2094 if (day > 31)
244 {
245 8 return(FX_INVALID_DAY);
246 }
247 2086 break;
248 }
249
250 8 default:
251
252 /* Invalid month. */
253 8 return(FX_INVALID_MONTH);
254 }
255
256 /* Check for invalid hour. */
257
2/2
✓ Branch 51 → 52 taken 16 times.
✓ Branch 51 → 53 taken 2206 times.
2222 if (hour > FX_MAXIMUM_HOUR)
258 {
259 16 return(FX_INVALID_HOUR);
260 }
261
262 /* Check for invalid minute. */
263
2/2
✓ Branch 53 → 54 taken 8 times.
✓ Branch 53 → 55 taken 2198 times.
2206 if (minute > FX_MAXIMUM_MINUTE)
264 {
265 8 return(FX_INVALID_MINUTE);
266 }
267
268 /* Check for invalid second. */
269
2/2
✓ Branch 55 → 56 taken 8 times.
✓ Branch 55 → 57 taken 2190 times.
2198 if (second > FX_MAXIMUM_SECOND)
270 {
271 8 return(FX_INVALID_SECOND);
272 }
273
274 /* Check for a valid caller. */
275
6/6
✓ Branch 57 → 58 taken 1440 times.
✓ Branch 57 → 60 taken 690 times.
✓ Branch 58 → 59 taken 750 times.
✓ Branch 58 → 60 taken 690 times.
✓ Branch 59 → 60 taken 690 times.
✓ Branch 59 → 61 taken 60 times.
2130 FX_CALLER_CHECKING_CODE
276
277 /* Call actual file date/time set service. */
278 120 status = _fx_file_date_time_set(media_ptr, file_name,
279 year, month, day,
280 hour, minute, second);
281
282 /* Return status to the caller. */
283 120 return(status);
284 }
285
286