繁体   English   中英

为什么realpath函数在Cygwin中不起作用?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM