From 7683f3d7488f4fc6e58bebe1d96fc13bba6ac802 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:37:31 +0000 Subject: [PATCH] [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> --- components/libc/posix/libdl/dlmodule.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/libc/posix/libdl/dlmodule.c b/components/libc/posix/libdl/dlmodule.c index 1b784bcae8..7ce6090877 100644 --- a/components/libc/posix/libdl/dlmodule.c +++ b/components/libc/posix/libdl/dlmodule.c @@ -41,8 +41,11 @@ static struct rt_module_symtab *_rt_module_symtab_end = RT_NULL; * @param name_size size of the name buffer * * @note This function extracts the base name without path and extension. - * For example: "/mnt/sdcard/apps/clock.so" -> "clock" - * For hidden files like ".hidden", the entire filename is used. + * Examples: + * - "/mnt/sdcard/apps/clock.so" -> "clock" + * - "/mnt/v1.2/app.so" -> "app" (dots in path are ignored) + * - ".hidden" -> ".hidden" (hidden files without extension) + * - ".hidden.so" -> ".hidden" (hidden files with extension) */ void dlmodule_extract_name(const char *path, char *name, int name_size) { @@ -77,15 +80,16 @@ void dlmodule_extract_name(const char *path, char *name, int name_size) /* determine end position for module name */ if (last_dot != RT_NULL && last_dot != first) { - /* extension found and filename doesn't start with dot */ + /* extension found (dot not at start of filename), strip it */ end = last_dot; } - /* else: no extension or filename starts with dot, use entire filename */ + /* else: no extension, or filename starts with dot only (e.g., ".hidden"), + * use entire filename */ size = end - first; if (size <= 0) { - /* edge case: empty filename or only dot(s) */ + /* defensive: empty path or path ending with "/" */ size = rt_strlen(first); } if (size >= name_size)