简体   繁体   English

Windows上的ANSI C文件权限?

[英]ANSI C File Permissions on Windows?

I am using CGYWIN gcc (4.8.2) and I am doing a very basic file open and write, but the resulting file has permissions that make it inaccessible to Windows. 我正在使用CGYWIN gcc(4.8.2),并且正在做一个非常基本的文件打开和写入操作,但是生成的文件具有使Windows无法访问的权限。 I don't understand why, and how can I fix this? 我不明白为什么,该如何解决?

// a bunch of curl stuff (CURLOPT_WRITEFUNCTION is write_data)
file = fopen(filename, "wb");
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
    size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
    return written;
}

The resulting file according to CGYWIN terminal is -rw-r--r-- but the file that I end up writing needs executable permissions, and I don't understand why the default on Windows doesn't have executable permissions? 根据CGYWIN终端生成的文件是-rw-r--r--但最终写入的文件需要可执行权限,而且我不明白为什么Windows上的默认文件没有可执行权限?

Windows' permissions are very different from Linux's, it uses the ACL model that allows a access control far more sophisticated than Linux's, and it can hardly be translated into this simpleton rwxrwxrwx flag set. Windows的权限与Linux的权限有很大不同,它使用ACL模型,该模型允许访问控制比Linux复杂得多,并且几乎不能将其转换为此simpleton rwxrwxrwx标志集。 But ironically Windows' ACL don't make distinction between "permission to read" and "permission to execute", to it it's the same thing. 但是具有讽刺意味的是,Windows的ACL并未在“读取权限”和“执行权限”之间进行区分,这是同一回事。 Perhaps Cygwin has it's own way of representing that, but I don't think thats the issue here. 也许Cygwin有它自己的表示方式,但是我不认为这是问题所在。 If you want to write to the file, you only need permission to write. 如果要写入文件,则只需要写入权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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