如何检查路径是否是另一个的子目录? 我想检查这个,因为我不想让用户前进到我的程序的 argv 给出的路径。
我做到了:
bool can_move(char *base, char *new)
{
return (strncmp(base, new, strlen(base)) == 0
&& (access(new, F_OK) == 0));
}
但问题是我如何管理 './' 和 '../' ?
谢谢!
答案 0 :(得分:1)
获取用户想要去的参数和路径的 realpath() 。 确保用户 realpath() 是参数 realpath() 或以参数 realpath()/
开头