c - getcwd()在什么情况下返回NULL?

标签 c getcwd

char cwd[256];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
    return -1;
}

首先想到的是,当 cwd 不够大时,getcwd() 可能会返回 NULL。还有其他情况吗?

最佳答案

Its documentation状态:

ERRORS

    The getcwd() function shall fail if:

    [EINVAL]
        The size argument is 0.
    [ERANGE]
        The size argument is greater than 0, but is smaller than the length of the pathname +1.

    The getcwd() function may fail if:

    [EACCES]
        Read or search permission was denied for a component of the pathname.
    [ENOMEM]
        Insufficient storage space is available.

关于c - getcwd()在什么情况下返回NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27798860/

相关文章:

c++ - 在函数中包装 C block 。初学者问题

c - $HOME 时 getcwd 错误

c - 使用线程的状态菜单

c - GSM PDU 解码算法行为异常

c++ - 是否有与 getcwd 等效的 C++?

c - 如果 getcwd() 和 getenv ("PWD") 不匹配,我该怎么办?

c - SDL_Mixer 无法处理部分代码

c - 联盟重复成员

C:指向结构中函数的指针

c - 获取当前目录的名称(不是路径)