char *path = "somefile.txt";
char resolved[PATH_MAX] = {0};
realpath(path, resolved);
printf("path is %s, resolved path is %s", path, resolved);
在linux env中,一切正常,但是如果它是在cygwin env中构建的,则解析为“”(空),为什么?
答案 0 :(得分:0)
realpath
函数的源位于文件canonicalize.c
中。有这样的代码:
if (resolved == NULL)
{
rpath = malloc (path_max);
if (rpath == NULL)
return NULL;
}
else
rpath = resolved;
我认为您用于数组resolved
库函数的初始化
感知为NULL
,并且没有保存到其中。
尝试初始化
char *resolved;
resolved=malloc(PATH_MAX);
/* SOME CODE */
free(resolved);