Skip to content

Commit 7683f3d

Browse files
CopilotBernardXiong
andcommitted
[libc][libdl] Improve documentation and comments for dlmodule_extract_name
Clarify the behavior of edge cases in documentation: - Added more examples to the function documentation - Fixed misleading comment about dot handling - Clarified the defensive check purpose Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
1 parent 79d6205 commit 7683f3d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

components/libc/posix/libdl/dlmodule.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ static struct rt_module_symtab *_rt_module_symtab_end = RT_NULL;
4141
* @param name_size size of the name buffer
4242
*
4343
* @note This function extracts the base name without path and extension.
44-
* For example: "/mnt/sdcard/apps/clock.so" -> "clock"
45-
* For hidden files like ".hidden", the entire filename is used.
44+
* Examples:
45+
* - "/mnt/sdcard/apps/clock.so" -> "clock"
46+
* - "/mnt/v1.2/app.so" -> "app" (dots in path are ignored)
47+
* - ".hidden" -> ".hidden" (hidden files without extension)
48+
* - ".hidden.so" -> ".hidden" (hidden files with extension)
4649
*/
4750
void dlmodule_extract_name(const char *path, char *name, int name_size)
4851
{
@@ -77,15 +80,16 @@ void dlmodule_extract_name(const char *path, char *name, int name_size)
7780
/* determine end position for module name */
7881
if (last_dot != RT_NULL && last_dot != first)
7982
{
80-
/* extension found and filename doesn't start with dot */
83+
/* extension found (dot not at start of filename), strip it */
8184
end = last_dot;
8285
}
83-
/* else: no extension or filename starts with dot, use entire filename */
86+
/* else: no extension, or filename starts with dot only (e.g., ".hidden"),
87+
* use entire filename */
8488

8589
size = end - first;
8690
if (size <= 0)
8791
{
88-
/* edge case: empty filename or only dot(s) */
92+
/* defensive: empty path or path ending with "/" */
8993
size = rt_strlen(first);
9094
}
9195
if (size >= name_size)

0 commit comments

Comments
 (0)