【发布时间】: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 再次检查