1 |
|
|
/**************************************************************************/ |
2 |
|
|
/* */ |
3 |
|
|
/* Copyright (c) Microsoft Corporation. All rights reserved. */ |
4 |
|
|
/* */ |
5 |
|
|
/* This software is licensed under the Microsoft Software License */ |
6 |
|
|
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ |
7 |
|
|
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ |
8 |
|
|
/* and in the root directory of this software. */ |
9 |
|
|
/* */ |
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_system.h" |
30 |
|
|
#include "fx_directory.h" |
31 |
|
|
#include "fx_utility.h" |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _fx_directory_name_extract PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function extracts the file name from the supplied input */ |
47 |
|
|
/* string. If there is nothing left after the extracted name, a NULL */ |
48 |
|
|
/* is returned to the caller. Otherwise, if something is left, a */ |
49 |
|
|
/* pointer to it is returned. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* source_ptr Source string pointer */ |
54 |
|
|
/* dest_ptr Destination string pointer */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* Pointer to Next Name (if multiple directories) */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* None */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* FileX System Functions */ |
67 |
|
|
/* */ |
68 |
|
|
/* RELEASE HISTORY */ |
69 |
|
|
/* */ |
70 |
|
|
/* DATE NAME DESCRIPTION */ |
71 |
|
|
/* */ |
72 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
73 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
74 |
|
|
/* resulting in version 6.1 */ |
75 |
|
|
/* */ |
76 |
|
|
/**************************************************************************/ |
77 |
|
261818 |
CHAR *_fx_directory_name_extract(CHAR *source_ptr, CHAR *dest_ptr) |
78 |
|
|
{ |
79 |
|
|
|
80 |
|
|
UINT i; |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
/* Set the destination string to NULL. */ |
84 |
|
261818 |
dest_ptr[0] = 0; |
85 |
|
|
|
86 |
|
|
/* Is a backslash present? */ |
87 |
✓✓✓✓
|
261818 |
if ((*source_ptr == '\\') || (*source_ptr == '/')) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
/* Advance the string pointer. */ |
91 |
|
58666 |
source_ptr++; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
/* Loop to remove any leading spaces. */ |
95 |
✓✓ |
262026 |
while (*source_ptr == ' ') |
96 |
|
|
{ |
97 |
|
|
|
98 |
|
|
/* Position past leading space. */ |
99 |
|
208 |
source_ptr++; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
/* Loop to extract the name. */ |
103 |
|
261818 |
i = 0; |
104 |
✓✓ |
2584437 |
while (*source_ptr) |
105 |
|
|
{ |
106 |
|
|
|
107 |
|
|
/* If another backslash is present, break the loop. */ |
108 |
✓✓✓✓
|
2337800 |
if ((*source_ptr == '\\') || (*source_ptr == '/')) |
109 |
|
|
{ |
110 |
|
|
break; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
/* Long name can be at most 255 characters, but are further limited by the |
114 |
|
|
FX_MAX_LONG_NAME_LEN define. */ |
115 |
✓✓ |
2322620 |
if (i == FX_MAX_LONG_NAME_LEN - 1) |
116 |
|
|
{ |
117 |
|
1 |
break; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/* Store the character. */ |
121 |
|
2322619 |
dest_ptr[i] = *source_ptr++; |
122 |
|
|
|
123 |
|
|
/* Increment the character counter. */ |
124 |
|
2322619 |
i++; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/* NULL-terminate the string. */ |
128 |
|
261818 |
dest_ptr[i] = 0; |
129 |
|
|
|
130 |
|
|
/* Determine if we can backup to the previous character. */ |
131 |
✓✓ |
261818 |
if (i) |
132 |
|
|
{ |
133 |
|
|
|
134 |
|
|
/* Yes, we can move backwards. */ |
135 |
|
261817 |
i--; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/* Get rid of trailing blanks in the destination string. */ |
139 |
✓✓ |
261869 |
while (dest_ptr[i] == ' ') |
140 |
|
|
{ |
141 |
|
|
|
142 |
|
|
/* Set this entry to NULL. */ |
143 |
|
51 |
dest_ptr[i] = 0; |
144 |
|
|
|
145 |
|
|
/* Backup to the next character. Since leading spaces have been removed, |
146 |
|
|
we know that the index is always greater than 1. */ |
147 |
|
51 |
i--; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/* Determine if the source string is now at the end. */ |
151 |
✓✓ |
261818 |
if (*source_ptr == 0) |
152 |
|
|
{ |
153 |
|
|
|
154 |
|
|
/* Yes, return a NULL pointer. */ |
155 |
|
246637 |
source_ptr = FX_NULL; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/* Return the last pointer position in the source. */ |
159 |
|
261818 |
return(source_ptr); |
160 |
|
|
} |
161 |
|
|
|