日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/8 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VS2005中,access对只读目录的属性判断不准确 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

只讀目錄,
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 <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; }

轉載于:https://www.cnblogs.com/java201408/archive/2009/09/25/3900994.html

總結

以上是生活随笔為你收集整理的VS2005中,access对只读目录的属性判断不准确的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。