gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 15:58:02 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com