0

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

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

为什么st_mode总是显示 6, When I compile in mingw

4

1 回答 1

1

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

stat(path, &stbuf) == -1

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

于 2012-07-30T08:28:52.813 回答