【问题标题】:stat() in mingw works incorrectlymingw 中的 stat() 工作不正确
【发布时间】:2012-04-22 14:32:55
【问题描述】:

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

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  

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

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?

【问题讨论】:

  • 使用 mingw 的 Dev C++ 对我来说效果很好。编译器版本是多少?你在使用任何 IDE 吗?
  • 我使用 cmake 版本 2.8.7 和 mingw gcc-core-4.6.1-2 进行编译。你可以用mingw gcc编译吗?我没用过IDE。我尝试在 Windows 上编译 genisoimage。
  • 我从here 下载了mingw,它对我来说非常好
  • 我也下载了mingw-get-inst-20111118.exe。请使用 gcc 编译器检查此代码
  • 我已经检查过了,它的工作原理,我认为你需要用新下载的 mingw 再次检查

标签: c mingw stat


【解决方案1】:

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

stat(path, &stbuf) == -1

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 2023-03-11
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多