VS2005中,access对只读目录的属性判断不准确
只讀目錄,
C:/>attrib +A +S +H +R testdir
C:/>attrib testdir
A? SHR???? C:/testdir
?
(1)VC6.0的執(zhí)行結(jié)果:
***********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的執(zhí)行結(jié)果
***********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!
?
結(jié)論:在VS2005中,使用access判斷的只讀目錄卻有【寫入】的屬性。
???????? 有什么高招,歡迎解答。
建議,在VS2005中對文件、目錄進(jìn)行權(quán)限校驗時,最好不要用access。
?
#include <stdio.h> #include <windows.h> #include <stdio.h> #include <io.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <stdio.h> #include <string.h> #include <time.h> 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; }
轉(zhuǎn)載于:https://www.cnblogs.com/java201408/archive/2009/09/25/3900994.html
總結(jié)
以上是生活随笔為你收集整理的VS2005中,access对只读目录的属性判断不准确的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jquery ui tabs详解(中文)
- 下一篇: 敏捷开发与中医理论系列之二:古法教学(软