GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fxe_file_date_time_set.c Lines: 70 70 100.0 %
Date: 2024-03-11 05:15:45 Branches: 63 63 100.0 %

Line Branch Exec Source
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
31
FX_CALLER_CHECKING_EXTERNS
32
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _fxe_file_date_time_set                             PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    William E. Lamie, Microsoft Corporation                             */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function checks for errors in the file date/time set service.  */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    media_ptr                             Media control block pointer   */
51
/*    file_name                             File name pointer             */
52
/*    year                                  Year                          */
53
/*    month                                 Month                         */
54
/*    day                                   Day                           */
55
/*    hour                                  Hour                          */
56
/*    minute                                Minute                        */
57
/*    second                                Second                        */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    return status                                                       */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    _fx_file_date_time_set                Actual file date/time set     */
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
/**************************************************************************/
81
458
UINT  _fxe_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name,
82
                              UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second)
83
{
84
85
UINT status;
86
87
88
    /* Check for a NULL media or file name pointer.  */
89

458
    if ((media_ptr == FX_NULL) || (file_name == FX_NULL))
90
    {
91
2
        return(FX_PTR_ERROR);
92
    }
93
94
    /* Check for invalid year.  */
95

456
    if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR))
96
    {
97
2
        return(FX_INVALID_YEAR);
98
    }
99
100
    /* Check for invalid day.  */
101
454
    if (day < 1)
102
    {
103
13
        return(FX_INVALID_DAY);
104
    }
105
106
    /* Check for invalid day.  */
107



441
    switch (month)
108
    {
109
110
7
    case 1:
111
    {
112
113
        /* Check for 31 days.  */
114
7
        if (day > 31)
115
        {
116
1
            return(FX_INVALID_DAY);
117
        }
118
6
        break;
119
    }
120
121
4
    case 2:
122
    {
123
124
        /* Check for leap year.  */
125
4
        if ((year % 4) == 0)
126
        {
127
128
            /* Leap year, February has 29 days.  */
129
2
            if (day > 29)
130
            {
131
1
                return(FX_INVALID_DAY);
132
            }
133
        }
134
        else
135
        {
136
137
            /* Otherwise, non-leap year.  February has
138
               28 days.  */
139
2
            if (day > 28)
140
            {
141
1
                return(FX_INVALID_DAY);
142
            }
143
        }
144
2
        break;
145
    }
146
147
2
    case 3:
148
    {
149
150
        /* Check for 31 days.  */
151
2
        if (day > 31)
152
        {
153
1
            return(FX_INVALID_DAY);
154
        }
155
1
        break;
156
    }
157
158
2
    case 4:
159
    {
160
161
        /* Check for 30 days.  */
162
2
        if (day > 30)
163
        {
164
1
            return(FX_INVALID_DAY);
165
        }
166
1
        break;
167
    }
168
169
2
    case 5:
170
    {
171
172
        /* Check for 31 days.  */
173
2
        if (day > 31)
174
        {
175
1
            return(FX_INVALID_DAY);
176
        }
177
1
        break;
178
    }
179
180
2
    case 6:
181
    {
182
183
        /* Check for 30 days.  */
184
2
        if (day > 30)
185
        {
186
1
            return(FX_INVALID_DAY);
187
        }
188
1
        break;
189
    }
190
191
2
    case 7:
192
    {
193
194
        /* Check for 31 days.  */
195
2
        if (day > 31)
196
        {
197
1
            return(FX_INVALID_DAY);
198
        }
199
1
        break;
200
    }
201
202
2
    case 8:
203
    {
204
205
        /* Check for 31 days.  */
206
2
        if (day > 31)
207
        {
208
1
            return(FX_INVALID_DAY);
209
        }
210
1
        break;
211
    }
212
213
2
    case 9:
214
    {
215
216
        /* Check for 30 days.  */
217
2
        if (day > 30)
218
        {
219
1
            return(FX_INVALID_DAY);
220
        }
221
1
        break;
222
    }
223
224
2
    case 10:
225
    {
226
227
        /* Check for 31 days.  */
228
2
        if (day > 31)
229
        {
230
1
            return(FX_INVALID_DAY);
231
        }
232
1
        break;
233
    }
234
235
2
    case 11:
236
    {
237
238
        /* Check for 30 days.  */
239
2
        if (day > 30)
240
        {
241
1
            return(FX_INVALID_DAY);
242
        }
243
1
        break;
244
    }
245
246
411
    case 12:
247
    {
248
249
        /* Check for 31 days.  */
250
411
        if (day > 31)
251
        {
252
1
            return(FX_INVALID_DAY);
253
        }
254
410
        break;
255
    }
256
257
1
    default:
258
259
        /* Invalid month.  */
260
1
        return(FX_INVALID_MONTH);
261
    }
262
263
    /* Check for invalid hour.  */
264
427
    if (hour > FX_MAXIMUM_HOUR)
265
    {
266
2
        return(FX_INVALID_HOUR);
267
    }
268
269
    /* Check for invalid minute.  */
270
425
    if (minute > FX_MAXIMUM_MINUTE)
271
    {
272
1
        return(FX_INVALID_MINUTE);
273
    }
274
275
    /* Check for invalid second.  */
276
424
    if (second > FX_MAXIMUM_SECOND)
277
    {
278
1
        return(FX_INVALID_SECOND);
279
    }
280
281
    /* Check for a valid caller.  */
282

423
    FX_CALLER_CHECKING_CODE
283
284
    /* Call actual file date/time set service.  */
285
15
    status =  _fx_file_date_time_set(media_ptr, file_name,
286
                                     year, month, day,
287
                                     hour, minute, second);
288
289
    /* Return status to the caller.  */
290
15
    return(status);
291
}
292