Skip to content

Commit 52e5d69

Browse files
guohao15xiaoxiang781216
authored andcommitted
api:add lib_realpath function
FAR char *lib_realpath(FAR const char *path, FAR char *resolved, bool notfollow); Signed-off-by: guohao15 <[email protected]>
1 parent 947b24c commit 52e5d69

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

include/nuttx/lib/lib.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ unsigned long nrand(unsigned long limit);
121121
FAR char *lib_get_pathbuffer(void);
122122
void lib_put_pathbuffer(FAR char *buffer);
123123

124+
/* Functions defined in lib_realpath.c **************************************/
125+
126+
FAR char *lib_realpath(FAR const char *path, FAR char *resolved,
127+
bool notfollow);
128+
124129
#undef EXTERN
125130
#ifdef __cplusplus
126131
}

libs/libc/stdlib/lib_realpath.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
* Public Functions
3737
****************************************************************************/
3838

39-
FAR char *realpath(FAR const char *path, FAR char *resolved)
39+
FAR char *lib_realpath(FAR const char *path, FAR char *resolved,
40+
bool notfollow)
4041
{
4142
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
4243
FAR char *wbuf[2] =
@@ -179,6 +180,13 @@ FAR char *realpath(FAR const char *path, FAR char *resolved)
179180
memcpy(&p[1], path, q - path);
180181
p[1 + q - path] = '\0';
181182

183+
if (notfollow)
184+
{
185+
p += 1 + q - path;
186+
path = q;
187+
goto loop;
188+
}
189+
182190
/* If this component is a symlink, toss it and prepend link
183191
* target to unresolved path.
184192
*/
@@ -266,3 +274,8 @@ FAR char *realpath(FAR const char *path, FAR char *resolved)
266274

267275
return NULL;
268276
}
277+
278+
FAR char *realpath(FAR const char *path, FAR char *resolved)
279+
{
280+
return lib_realpath(path, resolved, false);
281+
}

0 commit comments

Comments
 (0)