c - mingw 中的 stat() 工作不正确

标签 c mingw stat

我创建了一个简单的代码:

int main(int argc, char *argv[]) 
{
    struct stat eStat;
    int result;
    struct stat eStat2;
    int result2;

    result = stat("g:/temp/dvd", &eStat);
    printf("result=%d | eStat.st_mode=%d | S_IFMT=%d | S_IFDIR=%d\n",result,eStat.st_mode,S_IFMT,S_IFDIR);

    if((eStat.st_mode & S_IFMT) == S_IFDIR)
        printf("It is a dir!!!\n");
    else
        printf("not a dir\n");

    result2 = stat("g:\\temp\\test.txt", &eStat2); 
    printf("test.txt result2=%d | eStat2.st_mode=%d | S_IFMT=%d | S_IFDIR=%d\n",result2,eStat2.st_mode,S_IFMT,S_IFDIR);

    return 0;
}

我在VS2010(Windows7, C++)中编译此代码,输出:

result=0 | eStat.st_mode=16895 | S_IFMT=61440 | S_IFDIR=16384               
It is a dir!!!                    
test.txt result2=0 | eStat2.st_mode=33206 | S_IFMT=61440 | S_IFDIR=16384

我在Linux(Debian stable,gcc)中编译此代码,输出:

result=0 | eStat.st_mode=16877 | S_IFMT=61440 | S_IFDIR=16384      
It is a dir!!!                 
test.txt result2=0 | eStat2.st_mode=33188 | S_IFMT=61440 | S_IFDIR=16384  

当我在Windows7上的mingw(gcc)中编译时,输出:

result=0 | eStat.st_mode=6 | S_IFMT=61440 | S_IFDIR=16384           
not a dir                
test.txt result2=0 | eStat2.st_mode=6 | S_IFMT=61440 | S_IFDIR=16384

为什么在 mingw 中编译时,st_mode 总是显示 6?

最佳答案

为了使 stat()MinGW 下正常工作,您更改了哪些头文件?我怀疑我从测试中得到的结果

stat(path, &stbuf) == -1

但我不能确定,因为我在递归目录下降中使用它,并且我不知道可访问性测试是否(1)在下降的那个点是正确的,或者; (2) 检索正​​确的值以检查可访问性。

关于c - mingw 中的 stat() 工作不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10086425/

相关文章:

c++ - 代码块上的 Valgrind (linux)

c - parking 收费计划

c - mingw const char 字符串显然不是 const

C++ stat.h 类型不完整且无法定义

linux - 如何刷新 nfs 属性缓存?

c - 为什么scanf必须取operator的地址

c - 如何在 C 的命令行参数中传递空字符?

python - 在启用 GPU 的 Windows 8 上安装 theano

git - 我如何知道我安装了哪些版本的 MinGW32 和 MinGW64(通过 Git Bash)?

performance - Perl 的统计数据有更快的替代方案吗?