{"id":715,"date":"2010-07-01T01:18:06","date_gmt":"2010-07-01T07:18:06","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=715"},"modified":"2010-08-17T09:48:02","modified_gmt":"2010-08-17T15:48:02","slug":"creat%e5%8f%aa%e8%83%bd%e4%bb%a5%e5%8f%aa%e5%86%99%e6%96%b9%e5%bc%8f%e6%89%93%e5%bc%80%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/715","title":{"rendered":"creat\u53ea\u80fd\u4ee5\u53ea\u5199\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6"},"content":{"rendered":"<p>\u5728\u300alinuxC\u7f16\u7a0b\u5b9e\u6218\u300b\u4e66\u4e2d\uff0c\u6709\u4e00\u4e2amy_rwl.c\u7684\u5c0f\u7a0b\u5e8f\uff08\u8be6\u89c1P151\uff09\uff1a\u9996\u5148\u5229\u7528open\u51fd\u6570\u6216\u8005creat\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\uff0c\u5229\u7528write\u51fd\u6570\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\uff0c\u518d\u5229\u7528read\u51fd\u6570\u8bfb\u51fa\u6587\u4ef6\u4e2d\u6570\u636e\uff1b\u7528lseek\u79fb\u52a8\u6587\u4ef6\u6307\u9488\uff0c\u518d\u5199\u5165\u76f8\u540c\u7684\u6570\u636e\uff0c\u6700\u7ec8\u8bfb\u51fa\u6240\u6709\u6570\u636e\u3002\u521b\u5efa\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:\">\/\/ if((fd=creat(\"example_63.c\",S_IRWXU))==-1)\r\n\tif((fd=open(\"example_63.c\",O_CREAT|O_TRUNC|O_RDWR,S_IRWXU))==-1)\r\n\t{\r\n\t\tmy_err2(\"creat\",errno,__LINE__);\r\n\t}<\/pre>\n<p>\u5728\u8c03\u8bd5\u6b64\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u603b\u662f\u51fa\u73b0\u8fd9\u6837\u7684\u60c5\u51b5\uff1a\u5229\u7528open\u51fd\u6570\u521b\u5efa\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u4e00\u4e9b\u6b63\u5e38\u3002\u5229\u7528creat\u51fd\u6570\u521b\u5efa\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u8bfb\u51fa\u7684\u6570\u636e\u603b\u662f\u4e71\u7801\uff0c\u5e76\u4e14\u63d0\u793a\u8bfb\u5199\u5931\u8d25\u7684\u9519\u8bef\u4fe1\u606f\u3002\u5728\u81ea\u5df1\u5bfb\u6c42\u7ed3\u679c\u65e0\u671b\u7684\u65f6\u5019\uff0c\u5728chinaUnix\u8bba\u575b\u5f97\u5230\u4e86\u5e2e\u52a9\uff1acreat\u53ea\u80fd\u4ee5\u53ea\u5199\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6\u3002\u5176\u5b9e\u4e66\u4e0a\u6709\u8fd9\u53e5\u8bdd\uff0c\u53ef\u662f\u5728\u6211\u5bfb\u6c42\u4e0a\u8ff0\u9519\u8bef\u7b54\u6848\u7684\u65f6\u5019\uff0c\u4e5f\u6ca1\u6709\u6ce8\u610f\u5230\u5b83\u7684\u5b58\u5728\u3002\u800c\u4e14\u6211\u8fd8\u6709\u6709\u8fd9\u6837\u7684\u9519\u8bef\u6982\u5ff5\uff1a\u5373\u4fbfcreat\u51fd\u6570\u53ea\u80fd\u4ee5\u53ea\u5199\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6\uff0c\u53ef\u662f\u6211\u521b\u5efa\u7684\u65f6\u5019\u6709S_IRWXU\u53c2\u6570\uff0c\u90a3\u4e48\u5b83\u4fbf\u53ef\u4ee5\u5199\u4e86\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u8ba9\u6211\u91cd\u65b0\u7406\u89e3\u5b83\uff1a<\/p>\n<p>1.\u6587\u4ef6\u7684\u6253\u5f00\u65b9\u5f0f\u662f\u6307\u6587\u4ef6\u4ee5\u53ea\u8bfb\u3001\u53ea\u5199\u3001\u53ef\u8bfb\u5199\u90a3\u79cd\u65b9\u5f0f\u6253\u5f00\uff0c\u8fd4\u56de\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u53ef\u4ee5\u5bf9\u6b64\u6587\u4ef6\u8fdb\u884c\u76f8\u5e94\u7684\u8bfb\u5199\u64cd\u4f5c\u3002\u6bd4\u5982\u4e0a\u8ff0\u7684creat\u51fd\u6570\u5bf9example_63.c\u4ee5\u53ea\u5199\u65b9\u5f0f\u6253\u5f00\uff0c\u90a3\u4e48\u5c31\u53ea\u80fd\u5bf9\u8fd9\u4e2a\u6587\u4ef6\u8fdb\u884c\u5199\uff0c\u56e0\u6b64\u540e\u7eed\u7684\u8bfb\u64cd\u4f5c\u90fd\u5931\u8d25\u3002\u800copen\u521b\u5efa\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u6709O_RDWR\u53c2\u6570\uff0c\u56e0\u6b64\u53ef\u4ee5\u6210\u529f\u5bf9\u6587\u4ef6\u8bfb\u5199\u3002<\/p>\n<p>2.\u6587\u4ef6\u7684\u64cd\u4f5c\u6743\u9650\u662f\u6307\u7cfb\u7edf\u4e2d\u5404\u7528\u6237\u5bf9\u6b64\u6587\u4ef6\u7684\u4f7f\u7528\u6743\u9650\uff0c\u4f9d\u53c2\u6570\u800c\u5b9a\u3002<\/p>\n<p>3.\u4ee5\u521b\u5efa\u7684\u89d2\u5ea6\u6765\u770b\uff0ccreat\u548copen\u7684\u4f5c\u7528\u76f8\u540c\u3002\u4f46\u4ee5\u6253\u5f00\u6587\u4ef6\u7684\u65b9\u5f0f\u6765\u770b\uff0c\u524d\u8005\u53ea\u80fd\u4ee5\u53ea\u5199\u65b9\u5f0f\uff0c\u540e\u8005\u7531\u4e8e\u53c2\u6570\u7684\u5173\u7cfb\uff0c\u4ee5\u53ef\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00\u3002<\/p>\n<p>\u5982\u679c\u8981\u89e3\u51b3\u4e0a\u8ff0\u7684\u9519\u8bef\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728creat\u521b\u5efa\u5b8c\u6587\u4ef6\u540e\uff0c\u5173\u95ed\u6587\u4ef6\uff0c\u518d\u4ee5\u53ef\u8bfb\u5199\u7684\u65b9\u5f0f\uff0copen\u8fd9\u4e2a\u6587\u4ef6\u3002\u8fd9\u4e48\u505a\u662f\u5f88\u9ebb\u70e6\uff0c\u4f46\u662f\u8fd9\u91cc\u6211\u4eec\u4e3a\u4e86\u641e\u6e05\u695a\u4e24\u8005\u7684\u533a\u522b\uff0c\u4e5f\u65e0\u6240\u8c13\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u300alinuxC\u7f16\u7a0b\u5b9e\u6218\u300b\u4e66\u4e2d\uff0c\u6709\u4e00\u4e2amy_rwl.c\u7684\u5c0f\u7a0b\u5e8f\uff08\u8be6\u89c1P151\uff09\uff1a\u9996\u5148\u5229\u7528open\u51fd\u6570\u6216\u8005cre [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[109,108,107],"class_list":["post-715","post","type-post","status-publish","format-standard","hentry","category-linuxc","tag-c","tag-linux","tag-107"],"views":4975,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/715","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=715"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/715\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=715"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}