GCC Code Coverage Report


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

fx_directory_long_name_get_extended.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 /** Directory */
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_directory.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _fx_directory_long_name_get_extended PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function gets the long file name via the supplied short file */
45 /* name. If there is no long file name, the short file name will be */
46 /* returned. */
47 /* */
48 /* INPUT */
49 /* */
50 /* media_ptr Media control block pointer */
51 /* short_file_name Pointer to short (8.3) name */
52 /* long_file_name Pointer to long (max 255) name*/
53 /* long_file_name_buffer_length Buffer length for long name */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* return status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _fx_directory_search Search for the file name in */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /**************************************************************************/
68 72 UINT _fx_directory_long_name_get_extended(FX_MEDIA *media_ptr, CHAR *short_file_name, CHAR *long_file_name, UINT long_file_name_buffer_length)
69 {
70
71 UINT status;
72 UINT i;
73 FX_DIR_ENTRY dir_entry;
74
75
76 /* Setup pointer to media name buffer. */
77 72 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
78
79 /* Clear the short name string. */
80 72 dir_entry.fx_dir_entry_short_name[0] = 0;
81
82 /* If trace is enabled, insert this event into the trace buffer. */
83 FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_LONG_NAME_GET, media_ptr, short_file_name, long_file_name, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
84
85 /* Protect against other threads accessing the media. */
86 40 FX_PROTECT
87
88 /* Search the system for the supplied short directory name. */
89 72 status = _fx_directory_search(media_ptr, short_file_name, &dir_entry, FX_NULL, FX_NULL);
90
91 /* Determine if the search was successful. */
92
4/4
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 5 taken 28 times.
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 7 taken 35 times.
72 if (status != FX_SUCCESS)
93 {
94
95 /* Release media protection. */
96 5 FX_UNPROTECT
97
98 /* Return the error code. */
99 9 return(status);
100 }
101
102 /* Copy the long name portion into the destination string. */
103 63 i = 0;
104
11/11
✓ Branch 7 → 8 taken 1220 times.
✓ Branch 7 → 10 taken 4 times.
✓ Branch 8 → 9 taken 1200 times.
✓ Branch 8 → 10 taken 20 times.
✓ Branch 9 → 6 taken 1196 times.
✓ Branch 9 → 10 taken 1529 times.
✓ Branch 9 → 12 taken 5 times.
✓ Branch 10 → 11 taken 1500 times.
✓ Branch 10 → 12 taken 25 times.
✓ Branch 11 → 8 taken 1495 times.
✓ Branch 11 → 12 taken 5 times.
2754 while ((i < (FX_MAX_LONG_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_name[i]) && (i < (long_file_name_buffer_length - 1)))
105 {
106
107 /* Copy a character of the long name into the destination name. */
108 2691 long_file_name[i] = dir_entry.fx_dir_entry_name[i];
109
110 /* Move to next character. */
111 2691 i++;
112 }
113
114 /* Ensure the long file name is NULL terminated. */
115 63 long_file_name[i] = FX_NULL;
116
117 /* Check if the buffer is too short for the name. */
118
8/8
✓ Branch 10 → 11 taken 8 times.
✓ Branch 10 → 13 taken 20 times.
✓ Branch 11 → 12 taken 4 times.
✓ Branch 11 → 13 taken 4 times.
✓ Branch 12 → 13 taken 10 times.
✓ Branch 12 → 15 taken 25 times.
✓ Branch 13 → 14 taken 5 times.
✓ Branch 13 → 15 taken 5 times.
63 if ((i == (long_file_name_buffer_length - 1)) && (dir_entry.fx_dir_entry_name[i]))
119 {
120
121 /* Buffer too short, return error. */
122 9 status = FX_BUFFER_ERROR;
123 }
124
125 /* Release media protection. */
126 35 FX_UNPROTECT
127
128 /* Return the completion status. */
129 63 return(status);
130 }
131
132