{"id":1275,"date":"2010-09-07T09:33:17","date_gmt":"2010-09-07T01:33:17","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1275"},"modified":"2010-09-07T16:24:37","modified_gmt":"2010-09-07T08:24:37","slug":"%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b02","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1275","title":{"rendered":"\u6587\u4ef6\u64cd\u4f5c\u5b66\u4e60\u7b14\u8bb0(2)"},"content":{"rendered":"<p>8.\u719f\u6089\u4e86\u6587\u4ef6\u7684\u4e00\u4e9b\u57fa\u672c\u64cd\u4f5c\uff0c\u90a3\u4e48\u5c31\u8981\u6765\u7406\u89e3\u6587\u4ef6\u7684\u5c5e\u6027\u3002\u6bd4\u5982\u524d\u9762\u6211\u4eec\u505a\u8fc7cp\u547d\u4ee4\u7684\u5b9e\u73b0\uff0c\u524d\u9762\u6211\u4eec\u6240\u8bf4\u7684\u90a3\u4e9b\u51fd\u6570\u53ef\u4ee5\u5b8c\u6210\u6587\u4ef6\u5185\u5bb9\u7684\u590d\u5236\uff0c\u5982\u679c\u60f3\u83b7\u5f97\u67d0\u4e2a\u6587\u4ef6\u7684\u5c5e\u6027\u5c31\u8981\u7528\u5230stat\u51fd\u6570\u3002<\/p>\n<p>stat\u51fd\u6570\u65cf\u53ef\u4ee5\u5c06\u6587\u4ef6\u5c5e\u6027\u5b58\u50a8\u4e8estruct stat\u7c7b\u578b\u7684\u7ed3\u6784\u4f53\u4e2d\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4e2d\u7684\u51e0\u4e2a\u5e38\u7528\u5b57\u6bb5\uff0c\u6bd4\u5982st_ino\u662f\u6587\u4ef6\u7684\u7d22\u5f15\u8282\u70b9\u7f16\u53f7\uff1bst_mode\u662f\u6587\u4ef6\u7684\u7c7b\u578b\u548c\u8bbf\u95ee\u6743\u9650\uff0c\u6211\u4eec\u5728open\u6216chmod\u8fd9\u4e2a\u6587\u4ef6\u65f6\u5019\u90fd\u4f1a\u7528\u5230\u3002<\/p>\n<p>\u7279\u522b\u5f3a\u8c03\u7684\u662f\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4e2d\u6709\u4e09\u4e2a\u5173\u4e8e\u65f6\u95f4\u7684\u5b57\u6bb5\uff1ast_atime\u8868\u793a\u6587\u4ef6\u6700\u540e\u4e00\u6b21\u88ab\u8bbf\u95ee\u7684\u65f6\u95f4\uff1bst_mtime\u8868\u793a\u6587\u4ef6\u6700\u540e\u4e00\u6b21\u88ab\u4fee\u6539\u7684\u65f6\u95f4\uff0c\u8fd9\u91cc\u7684\u4fee\u6539\u7279\u522b\u6307\u6587\u4ef6\u5185\u5bb9\u7684\u4fee\u6539\uff1bst_ctime\u4e5f\u8868\u793a\u6587\u4ef6\u88ab\u4fee\u6539\u7684\u65f6\u95f4\uff0c\u4f46\u662f\u66f4\u5f3a\u8c03\u7684\u662f\u6587\u4ef6\u6743\u9650\u3001\u6240\u6709\u8005\u3001\u6240\u5c5e\u7ec4\u7684\u4fee\u6539\u65f6\u95f4\u3002\u5f53\u7136\u5185\u5bb9\u4fee\u6539\u65f6\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u4e5f\u4f1a\u76f8\u5e94\u66f4\u65b0\u3002<\/p>\n<p>\u800c\u4e14\u901a\u8fc7\u524d\u9762\u5bf9ls\u547d\u4ee4\u4ee5\u53cacp\u547d\u4ee4\u7684\u5b9e\u73b0\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u5173\u4e8est_mode\u6211\u4eec\u8fd8\u6709\u4e00\u4e9b\u5217\u7684\u5224\u5b9a\u5b8f\u3002\u6bd4\u5982S_ISLINK(st_mode)\uff0cS_ISDIR(st_mode)\u7b49\u7b49\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u7cfb\u7edf\u63d0\u4f9b\u7684\u51e0\u4e2a\u8bbf\u95ee\u6743\u9650\u5b8f\u4e0est_mode\u7684\u4e0e\u8fd0\u7b97\uff0c\u53ef\u4ee5\u5177\u4f53\u7684\u5206\u89e3st_mode\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">if((st_mode&amp;S_IROTH)==1)\r\n{\r\n      printf(\"the file can be read by others\\n!\");\r\n}<\/pre>\n<p>9.\u5982\u4f55\u8bbe\u7f6e\u6587\u4ef6\u5c5e\u6027\uff0c\u8fd9\u91cc\u6d89\u53ca\u5230\u4e00\u4e9b\u5e38\u7528\u51fd\u6570\u3002\u6bd4\u5982\u8981\u4fee\u6539\u6587\u4ef6\u7684\u5b58\u53d6\u6743\u9650\uff0c\u5c31\u7528chmod\/fchmod\u51fd\u6570\uff1b\u5982\u679c\u8981\u4fee\u6539\u6587\u4ef6\u7684\u7528\u6237id\u548c\u7ec4id\uff0c\u90a3\u4e48\u5c31\u7528chown\u7ec4\u51fd\u6570\u6765\u8fdb\u884c\u76f8\u5e94\u4fee\u6539\u3002\u6ce8\u610f\uff0c\u5982\u679c\u53ea\u60f3\u4fee\u6539\u4e24\u8005\u4e2d\u7684\u4e00\u4e2a\uff0c\u90a3\u4e48\u5c06\u4e24\u5916\u4e00\u4e2a\u7684\u503c\u6307\u5b9a\u4e3a-1\u5373\u53ef\u3002<\/p>\n<p>10.rename\u51fd\u6570\u7528\u6765\u4fee\u6539\u6587\u4ef6\u540d\u6216\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u5982\u679cnewpath\u6240\u6307\u5b9a\u7684\u6587\u4ef6\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u6e90\u6587\u4ef6\u4f1a\u88ab\u5220\u9664\u3002\u5982\u679c\u60f3\u5220\u9664\u4e00\u4e2a\u6587\u4ef6\uff0c\u90a3\u4e48\u5c31\u76f4\u63a5\u8c03\u7528remove\u51fd\u6570\u5373\u53ef\u3002\u6b64\u51fd\u6570\u65e2\u53ef\u4ee5\u5220\u9664\u4e00\u4e2a\u666e\u901a\u6587\u4ef6\uff0c\u4e5f\u53ef\u662f\u5220\u9664\u4e00\u4e2a\u76ee\u5f55\u6587\u4ef6\u3002\u8fd9\u4e2a\u51fd\u6570\u5176\u5b9e\u662f\u5c01\u88c5\u4e86unlink\u51fd\u6570\u548crmdir\u51fd\u6570\u3002\u5982\u679c\u60f3\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\u5219\u53ef\u4ee5\u4f7f\u7528mkdir\u51fd\u6570\u3002<\/p>\n<p>11.\u5982\u4f55\u83b7\u5f97\u4e00\u4e2a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u540d\u79f0\uff1f\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\u662f\u4e00\u4e2a\u7ecf\u5178\u6a21\u578b\u3002<\/p>\n<pre class=\"brush:c\">DIR *dir;\r\nstruct dirent *ptr;\r\n\r\nif((dir=opendir(path))==NULL)\r\n{\r\n\tperror(\"opendir\");\r\n\treturn -1;\r\n}\r\nwhile((ptr=readdir(dir))!=NULL)\r\n{\r\n\tprintf(\"file name:%s\\n\",ptr-&gt;d_name);\r\n}\r\n\/*do something*\/\r\nclosedir(dir);<\/pre>\n<p>\u9996\u5148\u901a\u8fc7opendir\u6253\u5f00\u4e00\u4e2a\u76ee\u5f55\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2aDIR*\u7684\u76ee\u5f55\u6d41dir\uff0c\u8fd9\u7c7b\u4f3c\u4e8e\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08\u8fd9\u91cc\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u76ee\u5f55\u63cf\u8ff0\u7b26\uff09\u3002\u7136\u540e\u5c06\u8fd9\u4e2adir\u4f5c\u4e3areaddir\u51fd\u6570\u7684\u53c2\u6570\uff0c\u4f7f\u7528\u4e00\u4e2awhile\u5faa\u73af\u5c31\u53ef\u4ee5\u4f9d\u6b21\u83b7\u5f97\u8be5\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u4fe1\u606f\uff0c\u5b58\u50a8\u4e8estruct dirent\u7c7b\u578b\u7684\u7ed3\u6784\u4f53\u4e2d\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u5982\u4f55\u6839\u636e\u4e0a\u9762\u7684\u57fa\u672c\u6a21\u578b\u53bb\u5b9e\u73b0\u5176\u4ed6\u7684\u529f\u80fd\uff1f\u4f60\u53ef\u4ee5\u8fd9\u4e48\u60f3\uff1a\u65e2\u7136\u73b0\u5728\u5df2\u7ecf\u5f97\u5230\u4e86\u6bcf\u4e2a\u6587\u4ef6\u7684\u540d\u79f0\uff0c\u90a3\u4e48\u60f3\u5b8c\u6210\u5355\u4e2a\u6587\u4ef6\u7684\u64cd\u4f5c\u5c31\u5bb9\u6613\u591a\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>8.\u719f\u6089\u4e86\u6587\u4ef6\u7684\u4e00\u4e9b\u57fa\u672c\u64cd\u4f5c\uff0c\u90a3\u4e48\u5c31\u8981\u6765\u7406\u89e3\u6587\u4ef6\u7684\u5c5e\u6027\u3002\u6bd4\u5982\u524d\u9762\u6211\u4eec\u505a\u8fc7cp\u547d\u4ee4\u7684\u5b9e\u73b0\uff0c\u524d\u9762\u6211\u4eec\u6240\u8bf4\u7684\u90a3\u4e9b\u51fd\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1275","post","type-post","status-publish","format-standard","hentry","category-linuxc"],"views":4251,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=1275"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1275\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1275"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}