[英]Why does the realpath function not work in Cygwin?
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中构建的,则解析为“”(空),为什么?
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.