diff --git a/include/nuttx/lib/lib.h b/include/nuttx/lib/lib.h index 547d8367b7..dc3b2e5398 100644 --- a/include/nuttx/lib/lib.h +++ b/include/nuttx/lib/lib.h @@ -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 } diff --git a/libs/libc/stdlib/lib_realpath.c b/libs/libc/stdlib/lib_realpath.c index 6603f19466..596f244cb6 100644 --- a/libs/libc/stdlib/lib_realpath.c +++ b/libs/libc/stdlib/lib_realpath.c @@ -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); +}