mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 08:38:38 +08:00
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:
parent
947b24c8c1
commit
52e5d69236
2 changed files with 19 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue