Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C stat()函数报告Windows桌面文件夹为只读_Windows_Desktop_Stat - Fatal编程技术网

C stat()函数报告Windows桌面文件夹为只读

C stat()函数报告Windows桌面文件夹为只读,windows,desktop,stat,Windows,Desktop,Stat,显然,我的桌面不是只读的,但是stat()和findfirst()函数将其报告为不可写。我应该使用其他函数吗?为什么? #include <iostream> #include <ShlObj.h> #include <sys/stat.h> int main() { PWSTR ppszPath; if (::SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &ppszPath)==S_

显然,我的桌面不是只读的,但是stat()和findfirst()函数将其报告为不可写。我应该使用其他函数吗?为什么?

#include <iostream>
#include <ShlObj.h>
#include <sys/stat.h>

int main() {
    PWSTR ppszPath;
    if (::SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &ppszPath)==S_OK) {
        std::wcout << L"Desktop folder: " << ppszPath << L"\n";
        struct _stat64 buf;
        if (_wstat64(ppszPath, &buf)==0) {
            std::wcout << L"Writable: " << ( (buf.st_mode & _S_IWRITE) != 0? "yes": "no") << L"\n";
        }
    }
}

目录的“只读”标志是装饰性的,并且是透明的。在目录中创建文件由
FILE\u ADD\u FILE
控制,在目录中删除文件由
FILE\u DELETE\u CHILD
控制,创建子目录由
FILE\u ADD\u subdirectory
控制。谢谢,我希望能在stat()的文档中找到这些信息由于这与相应的Posix行为不同,但显然这是不需要的。Windows安全模型比Posix更复杂,因此任何映射都必然不完整。
stat
函数非常懒惰,只使用文件属性。有一点需要澄清:只读标志不完全是装饰性的,它确实阻止删除目录。
Desktop folder: C:\Users\heldepn\Desktop
Writable: no