api:add lib_realpath function

FAR char *lib_realpath(FAR const char *path, FAR char *resolved, bool notfollow);

Signed-off-by: guohao15 <guohao15@xiaomi.com>
This commit is contained in:
guohao15 2023-10-27 15:29:41 +08:00 committed by Xiang Xiao
parent 947b24c8c1
commit 52e5d69236
2 changed files with 19 additions and 1 deletions

View file

@ -121,6 +121,11 @@ unsigned long nrand(unsigned long limit);
FAR char *lib_get_pathbuffer(void);
void lib_put_pathbuffer(FAR char *buffer);
/* Functions defined in lib_realpath.c **************************************/
FAR char *lib_realpath(FAR const char *path, FAR char *resolved,
bool notfollow);
#undef EXTERN
#ifdef __cplusplus
}

View file

@ -36,7 +36,8 @@
* Public Functions
****************************************************************************/
FAR char *realpath(FAR const char *path, FAR char *resolved)
FAR char *lib_realpath(FAR const char *path, FAR char *resolved,
bool notfollow)
{
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
FAR char *wbuf[2] =
@ -179,6 +180,13 @@ loop:
memcpy(&p[1], path, q - path);
p[1 + q - path] = '\0';
if (notfollow)
{
p += 1 + q - path;
path = q;
goto loop;
}
/* If this component is a symlink, toss it and prepend link
* target to unresolved path.
*/
@ -266,3 +274,8 @@ out:
return NULL;
}
FAR char *realpath(FAR const char *path, FAR char *resolved)
{
return lib_realpath(path, resolved, false);
}