有关_S_IFDIR的设定问题
看了SYS\STAT.H.中结构体_stat的定义,其中st_mode的取值中有_S_IFDIR这一项,表示D
irectory的意思:
#define _S_IFDIR 0040000 /* directory */
在网上看解释说如果路径指定的是目录,则要设置_S_IFDIR位。
我的疑问是既然采用了宏定义,那么_S_IFDIR 应是个常量,既然是常量那怎么还能对其进
行设定呢?
自己动手写了段代码:
#include <io.h>
#include <fcntl.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<iostream.h>
void main( void )
{
struct _stat buf;
int fh,result;
fh = _open( "juve.txt", _O_CREAT | _O_RDONLY);
result = _fstat( fh, &buf );
cout<<"the value of _S_IFDIR is "<<(buf.st_mode & _S_IFDIR)<<endl;
_close( fh );
}
juve.txt是自己建的文本文档,里面有一段文字。
程序运行的结果是the value of _S_IFDIR is 0
有点疑惑_S_IFDIR的值为什么不是0040000 ?如果能对其进行设定的话该怎样做?
请大虾们赐教!
[解决办法]
_S_IFDIR不能自己设的