您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

VS2005中,access对只读目录的属性判断不准确

2024/11/15 22:25:05发布17次查看
只读目录, c:/attrib +a +s +h +r testdir c:/attrib testdir a shr c:/testdir (1)vc6.0的执行结果: ***********test stat*********************** file [c:/testdir] exists! file [c:/testdir] is directory! file [c:/testdir] can be read! file [c:/
只读目录,
c:/>attrib +a +s +h +r testdir
c:/>attrib testdir
a  shr     c:/testdir
(1)vc6.0的执行结果:
***********test stat***********************
file [c:/testdir] exists!
file [c:/testdir] is directory!
file [c:/testdir] can be read!
file [c:/testdir] can not be writed!
***********test access***********************
file [c:/testdir] exists!
file [c:/testdir] can not be writed!
file [c:/testdir] can be read!
(2)vs2005的执行结果
***********test stat***********************
file [c:/testdir] exists!
file [c:/testdir] is directory!
file [c:/testdir] can be read!
file [c:/testdir] can not be writed!
***********test access***********************
file [c:/testdir] exists!
file [c:/testdir] can be writed!
file [c:/testdir] can be read!
结论:在vs2005中,使用access判断的只读目录却有【写入】的属性。
         有什么高招,欢迎解答。
建议,在vs2005中对文件、目录进行权限校验时,最好不要用access。
#include #include #include #include #include #include #include #include #include #include int main(int argc ,char *argv[]){ struct stat buf; int ret = 0; int i=0; char *file = c://testdir; printf(***********test stat***********************/n); ret = stat(file, &buf ); if(ret != 0) { printf(stat [%s] fail, errno=%d/n, file, errno); return -1; } else printf(file [%s] exists!/n, file); if((buf.st_mode&s_ifdir)==0) printf(file [%s] is not directory!/n, file); else printf(file [%s] is directory!/n, file); if((buf.st_mode&s_iread)!=0) printf(file [%s] can be read!/n, file); else printf(file [%s] can not be read!/n, file); if((buf.st_mode&s_iwrite)!=0) printf(file [%s] can be writed!/n, file); else printf(file [%s] can not be writed!/n, file); printf(/n***********test access***********************/n); if ((ret = access(file, 0))==0) { printf(file [%s] exists!/n, file); } else printf(file [%s] not exists!/n, file); if ((ret = access(file, 2))==0) { printf(file [%s] can be writed!/n, file); } else printf(file [%s] can not be writed!/n, file); if ((ret = access(file, 4))==0) { printf(file [%s] can be read!/n, file); } else printf(file [%s] can not be read!/n, file); return 0; }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product