{"id":960,"date":"2010-08-03T14:59:03","date_gmt":"2010-08-03T20:59:03","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=960"},"modified":"2010-08-03T20:41:44","modified_gmt":"2010-08-04T02:41:44","slug":"%e5%ae%9e%e7%8e%b0chmod%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/960","title":{"rendered":"\u5b9e\u73b0chmod\u547d\u4ee4"},"content":{"rendered":"<p>\u300aLinuxC\u7f16\u7a0b\u5b9e\u6218\u300b\u4e00\u4e66\u4e2d\u5728\u4ecb\u7ecd\u6587\u4ef6\u64cd\u4f5c\u90e8\u5206\u7684\u65f6\u5019\uff0c\u4e00\u5f00\u59cb\u5c31\u7ed9\u6211\u4eec\u4e3e\u4e86\u4e2a\u5b9e\u73b0my_chmod\u7684\u5c0f\u7a0b\u5e8f\u3002\u5b83\u53ea\u652f\u6301\u7eaf\u6570\u5b57\u7684\u6743\u9650\u65b9\u5f0f\uff0c\u4e0d\u652f\u6301\u53c2\u6570\u662f:\u6743\u9650\u8303\u56f4+\/-\/=\u6743\u9650\u8bbe\u7f6e\u8fd9\u6837\u7684\u5f62\u5f0f\u3002\u56e0\u6b64\u6211\u4eec\u8981\u5b9e\u73b0\u7684my_chmod\u8981\u80fd\u591f\u652f\u6301\u8fd9\u79cd\u5f62\u5f0f\u3002\u5177\u4f53\u7684\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n<p>my_chmod\u80fd\u591f\u4f9d\u7167\u6743\u9650\u8bbe\u7f6e\u6539\u53d8\u6587\u4ef6\u7684\u6743\u9650\u3002\u6743\u9650\u65e2\u53ef\u4ee5\u662f\u4ee3\u8868\u6027\u7684\u6570\u5b57\uff0c\u4e5f\u53ef\u4ee5\u662f\u7b26\u53f7\uff08\u6743\u9650\u8303\u56f4+\/-\/=\u6743\u9650\u8bbe\u7f6e\uff09\u3002\u5e76\u4e14\u591a\u4e2a\u7b26\u53f7\u4e4b\u95f4\u53ef\u4ee5\u7528\u9017\u53f7\u9694\u5f00\u3002\u672c\u6587\u4e2d\u7684my_chmod\u53ea\u652f\u6301\u6bcf\u4e2a\u7b26\u53f7\u4e2d\u53ea\u6709\u4e00\u4e2a+\/-\/=\u7684\u60c5\u51b5\u3002\u6bd4\u5982\uff1a.\/my_chmod u+g+o filename \u8fd9\u6837\u7684\u5f62\u5f0f\u672c\u7a0b\u5e8f\u5e76\u4e0d\u652f\u6301\uff08\u5c3d\u7ba1chmod\u652f\u6301\uff09\u3002<\/p>\n<p>\u9274\u4e8e\u672c\u535a\u5ba2\u524d\u6587\u4e2d\u5df2\u7ecf\u8be6\u7ec6\u8bb2\u89e3\u4e86my_cp\uff0c\u56e0\u6b64\u672c\u6587\u91cd\u70b9\u8bf4\u660e\u5982\u4f55\u5c06\u7b26\u53f7\u6743\u9650\u8bbe\u7f6e\u7684\u65b9\u5f0f\u8f6c\u5316\u6210\u6570\u5b57\u5f62\u5f0f\u3002\u81f3\u4e8e\u7b26\u53f7\u6743\u9650\u8bbe\u7f6e\u7684\u5408\u6cd5\u6027\u5224\u65ad\u7b49\u7b49\uff0c\u65e0\u975e\u662f\u5229\u7528C\u8bed\u8a00\u57fa\u7840\u77e5\u8bc6\u6765\u5224\u65ad\uff0c\u5f53\u7136\u8fd9\u8981\u5efa\u7acb\u5728\u719f\u6089chmod\u547d\u4ee4\u7684\u57fa\u7840\u4e0a\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u6211\u4eec\u5f00\u59cb\u5427\uff01<\/p>\n<p>\u5c06\u7b26\u53f7\u6743\u9650\u8f6c\u6362\u6210\u6570\u5b57\u6743\u9650\u662f\u901a\u8fc7check_option\u548cget_mode\u4e24\u4e2a\u51fd\u6570\u5b8c\u6210\u7684\u3002check_option\u51fd\u6570\u9996\u5148\u5224\u65ad\u7b26\u53f7\u6743\u9650\u7684\u4f4d\u7f6e\u5408\u6cd5\u6027\u3002\u7531\u4e8e\u591a\u4e2a\u7b26\u53f7\u53c2\u6570\u53ef\u4ee5\u7528\u9017\u53f7\u9694\u5f00\uff0c\u56e0\u6b64\u5728\u6b64\u51fd\u6570\u4e2d\u4f9d\u6b21\u8c03\u7528get_mode\u51fd\u6570\uff0c\u6700\u540e\u5c06\u5f97\u5230\u6700\u7ec8\u7684mode\u3002\u6bd4\u5982\uff1a.\/my_chmod u+rw,go+w test.c;\u90a3\u4e48\u5728check_option\u51fd\u6570\u4e2d\u5206\u522b\u5bf9\u4e24\u7ec4\u7b26\u53f7\u53c2\u6570\uff08u+rw\u548cgo+w\uff09\u8c03\u7528get_mode\u51fd\u6570\u3002\u4e24\u6b21\u8c03\u7528\u4f7f\u5f97mode\u4e3a\uff1arw- -w- -w-(622)\u3002\u4f46\u662f\u8fd9\u65f6\u7684mode\u5e76\u4e0d\u662f\u6587\u4ef6\u6700\u7ec8\u7684mode\uff0c\u8fd8\u8981\u770b\u6587\u4ef6\u5728\u6267\u884cmy_chmod\u4e4b\u524d\u7684\u6743\u9650\uff0c\u5982\u679ctest.c \u672c\u8eab\u6743\u9650\u4e3a644\uff0c\u90a3\u4e48my_chmod\u6267\u884c\u540e\uff0c\u6587\u4ef6\u6743\u9650\u4e3a666\u3002<\/p>\n<p>\u5f53\u8fd9\u53ea\u662f+\u60c5\u51b5\uff0c\u5bf9\u4e8e-\u548c=\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u4e0b\u9762\u4f1a\u8be6\u7ec6\u8bf4\u660e\u3002<\/p>\n<p>\u6211\u4eec\u518d\u6765\u770bget_mode\u51fd\u6570\u7684\u539f\u578b\uff1a<\/p>\n<pre class=\"brush:c\">void get_mode(int u,int g,int o,int r,int w,int x,int sign,mode_t* mode);<\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u4e00\u5f00\u59cb\u770b\u597d\u50cf\u5f88\u590d\u6742\uff0c\u56e0\u4e3a\u6709\u4f17\u591a\u7684\u53c2\u6570\uff0c\u5176\u5b9e\u4e00\u70b9\u90fd\u4e0d\u590d\u6742\u3002\u53c2\u6570u,g,o\u5206\u522b\u5bf9\u5e94\u7528\u6237\uff0c\u7528\u6237\u7ec4\uff0c\u5176\u4ed6\u6210\u5458\uff1b\u800cr,w,x\u5f53\u7136\u662f\u53ef\u8bfb\uff0c\u53ef\u5199\uff0c\u53ef\u6267\u884c\uff1bsign\u6839\u636e\u503c1\uff0c2\uff0c3\u5206\u522b\u5bf9\u5e94\u7684\u662f+\uff0c-\uff0c=\uff1b\u672b\u5c3e\u7684mode\u662f\u5c06\u6e90\u6587\u4ef6\u7684mode\u4f20\u8fc7\u6765\uff0c\u56e0\u4e3a\u8981\u4fdd\u5b58\u5176\u503c\uff0c\u6240\u4ee5\u4f20\u6765\u7684\u662f\u6307\u9488\u3002\u8fd9\u4e9b\u53d8\u91cf\u5982\u679c\u4e3a1\u90a3\u4e48\u8bf4\u660e\u5728\u53c2\u6570\u4e2d\u51fa\u73b0\u8fc7\uff0c\u5426\u5219\u6ca1\u6709\u51fa\u73b0\u3002\u8fd9\u4e9b\u53d8\u91cf\u7684\u8d4b\u503c\u5728check_option\u51fd\u6570\u4e2d\u5b8c\u6210\u3002<\/p>\n<p>\u5728get_mode\u51fd\u6570\u4e2d\uff0c\u7528\u4e00\u4e2aswitch\u8bed\u53e5\u6765\u533a\u5206+\uff0c-\uff0c=\u7684\u4e0d\u540c\u529f\u80fd\u3002<\/p>\n<pre class=\"brush:c\">\tswitch(sign)\r\n\t{\r\n\t\tcase 1:\/\/+\r\n\t\t\t{\r\n\t\t\t\t\/\/the code was omited\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase 2:\/\/-\r\n\t\t\t{\r\n\t\t\t\t\/\/the code was omited\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase 3:\/\/=\r\n\t\t\t{\r\n\t\t\t\t\/\/the code was omited\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tprintf(\"sign error\\n\");\r\n\t\t\texit(1);\r\n\t}<\/pre>\n<p>\u9996\u5148\u6765\u770bcase1\uff0c\u5b83\u5bf9\u5e94\u7684\u662f+\u3002\u8fd9\u91cc\u7684+\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u5c31\u662f\u5728\u6587\u4ef6\u539f\u6765\u7684\u6743\u9650\u57fa\u7840\u4e0a\u518d\u52a0\u4e0a\u547d\u4ee4\u4e2d\u7684\u6743\u9650\u3002\u8fd9\u91ccu,g,o\u4e09\u4e2a\u7ec4\u5206\u522b\u5bf9\u5e94\u4e09\u4e2aif\u8bed\u53e5\uff0c\u518d\u9488\u5bf9\u5177\u4f53\u4e00\u4e2a\u7ec4\uff0c\u67e5\u770b\u8fd9\u4e2a\u7ec4\u5177\u6709r,w,x\u6743\u9650\u7684\u90a3\u51e0\u4e2a\uff08\u518d\u5206\u522b\u5bf9\u5e94\u4e09\u4e2aif\u8bed\u53e5\uff09\u3002\u6bd4\u5982\uff1a.\/my_chmod ug+rwx,o+r test.c\uff1b\u9996\u5148\u4ed6\u4f1a\u8fdb\u5165\u7b2c\u4e00\u4e2aif(u)\u8bed\u53e5\uff0c\u53c8\u56e0\u4e3a\u53c2\u6570\u4e2d\u53c8\u51fa\u73b0\u4e86rwx\uff0c\u56e0\u6b64if(u)\u4e2d\u7684\u4e09\u4e2aif\u8bed\u53e5\u90fd\u4f1a\u88ab\u6267\u884c\u3002\u63a5\u7740\uff0c\u53c8\u4f1a\u4ee5\u7c7b\u4f3c\u7684\u8fc7\u7a0b\u53bb\u6267\u884cif(g)\u3002\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u4e00\u6b21get_mode\u7684\u8c03\u7528\uff0c\u81f3\u4e8eo+r\uff0c\u5b83\u5c5e\u4e8e\u7b2c\u4e8c\u6b21\u8c03\u7528get_mode\u51fd\u6570\u3002<\/p>\n<p>\u65e2\u7136\u53c2\u6570\u4e2d\u51fa\u73b0\u4e86rwx\uff0c\u5982\u4f55\u8ba9mode\u5177\u6709\u5bf9\u5e94\u7684rwx\u6743\u9650\uff1f\u5982\u4f55\u4f53\u73b0\u5728\u5177\u4f53\u7684\u4ee3\u7801\u4e0a\uff1f\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u6216\u8fd0\u7b97\uff0c\u4f46\u662f\u6ce8\u610f\u4e00\u5b9a\u662f\u6587\u4ef6\u672c\u8eab\u7684mode\u5206\u522b\u4e0e\u76f8\u5e94\u7684\u6743\u9650\u53bb\u6216\u3002\u8fd9\u91cc\u91c7\u7528\u4e86\u4e00\u7cfb\u5217\u7684\u5b8f\uff0c\u6781\u5927\u7684\u65b9\u4fbf\u4e86\u4ee3\u7801\u7684\u7f16\u5199\u3002\u5982\u679c\u4f60\u5bf9\u6b64\u5904\u91c7\u7528\u6216\u8fd0\u7b97\u611f\u5230\u56f0\u60d1\uff0c\u90a3\u4e48\u4e0d\u59a8\u624b\u52a8\u53bb\u8bd5\u8bd5\uff0c\u5373\u53ef\u660e\u767d\u3002\u5177\u4f53\u7684\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:c\">\t\tcase 1:\r\n\t\t\t{\r\n\t\t\t\tif(u)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(r)\r\n\t\t\t\t\t\t*mode|=S_IRUSR;\r\n\t\t\t\t\tif(w)\r\n\t\t\t\t\t\t*mode|=S_IWUSR;\r\n\t\t\t\t\tif(x)\r\n\t\t\t\t\t\t*mode|=S_IXUSR;\r\n\t\t\t\t}\r\n\t\t\t\tif(g)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(r)\r\n\t\t\t\t\t\t*mode|=S_IRGRP;\r\n\t\t\t\t\tif(w)\r\n\t\t\t\t\t\t*mode|=S_IWGRP;\r\n\t\t\t\t\tif(x)\r\n\t\t\t\t\t\t*mode|=S_IXGRP;\r\n\t\t\t\t}\r\n\t\t\t\tif(o)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(r)\r\n\t\t\t\t\t\t*mode|=S_IROTH;\r\n\t\t\t\t\tif(w)\r\n\t\t\t\t\t\t*mode|=S_IWOTH;\r\n\t\t\t\t\tif(x)\r\n\t\t\t\t\t\t*mode|=S_IXOTH;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;<\/pre>\n<p>\u63a5\u7740\u770bcase2\uff0c\u5bf9\u5e94\u7684\u7b26\u53f7\u662f-\u3002\u5b83\u4e0e\u4e0a\u9762\u7684+\u521a\u597d\u76f8\u53cd\uff1a\u5728\u6587\u4ef6\u539f\u6765\u7684\u6743\u9650\u4e0a\u51cf\u53bb\u547d\u4ee4\u4e2d\u6240\u8f93\u5165\u7684\u6743\u9650\u3002\u8fd9\u4e2a\u52a8\u4f5c\u5728\u4ee3\u7801\u4e2d\u4e5f\u5f88\u597d\u4f53\u73b0\uff0c\u7528\u5f02\u6216\u5373\u53ef\u3002\u56e0\u4e3a1^1=0,1^0=1\uff0c\u8fd9\u6837\u4f7f\u5f97\u4e0e\u76f8\u5e94\u5b8f\u5f02\u6216\u7684\u90a3\u4e2a\u6743\u9650\u4e3a0\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u91cc\u8fd8\u5e94\u8be5\u6ce8\u610f\u4e00\u4e2a\u95ee\u9898\uff0c\u521a\u624d\u6211\u4eec\u6240\u5206\u6790\u7684\u662f\u5f53\u8fd9\u4e2a\u6743\u9650\u5b58\u5728\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5f02\u6216\u6765\u505a\u76f8\u5e94\u7684\u201c\u51cf\u201d\uff0c\u5982\u679c\u547d\u4ee4\u4e2d\u8981\u51cf\u53bb\u7684\u6743\u9650\uff0c\u6587\u4ef6\u672c\u8eab\u5c31\u4e0d\u5177\u6709\uff0c\u90a3\u4e48\u5f02\u6216\u540e\u53c8\u4f1a\u4f7f\u5f97\u6587\u4ef6\u5177\u6709\u4e86\u8fd9\u4e2a\u6743\u9650\uff01\u56e0\u6b64\u6211\u4eec\u5e94\u8be5\u5728\u5c0fif\u8bed\u53e5\u7684\u5224\u65ad\u5904\u52a0\u4e0a\u4e00\u4e2a\u4e0e\u8fd0\u7b97\uff1a\u5224\u65ad\u6b64\u65f6\u6587\u4ef6\u7684\u6743\u9650\u662f\u5426\u542b\u6709\u8981\u51cf\u53bb\u7684\u6743\u9650\u3002\u81f3\u4e8e\u8fd9\u91cc\u4e3a\u4f55\u7528\u5f02\u6216\uff0c\u4e0e\u8fd0\u7b97\uff0c\u8bf7\u81ea\u5df1\u4e3e\u4f8b\uff0c\u624b\u52a8\u8fd0\u7b97\u5373\u53ef\u660e\u767d\u3002<\/p>\n<pre class=\"brush:c\">\t\tcase 2:\r\n\t\t\t{\r\n\t\t\t\tif(u)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(r&amp;&amp;(*mode&amp;S_IRUSR))\r\n\t\t\t\t\t\t*mode^=S_IRUSR;\r\n\t\t\t\t\tif(w&amp;&amp;(*mode&amp;S_IWUSR))\r\n\t\t\t\t\t\t*mode^=S_IWUSR;\r\n\t\t\t\t\tif(x&amp;&amp;(*mode&amp;S_IXUSR))\r\n\t\t\t\t\t\t*mode^=S_IXUSR;\r\n\t\t\t\t}\r\n\t\t\t\tif(g)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(r&amp;&amp;(*mode&amp;S_IRGRP))\r\n\t\t\t\t\t\t*mode^=S_IRGRP;\r\n\t\t\t\t\tif(w&amp;&amp;(*mode&amp;S_IWGRP))\r\n\t\t\t\t\t\t*mode^=S_IWGRP;\r\n\t\t\t\t\tif(x&amp;&amp;(*mode&amp;S_IXGRP))\r\n\t\t\t\t\t\t*mode^=S_IXGRP;\r\n\t\t\t\t}\r\n\t\t\t\tif(x)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(r&amp;&amp;(*mode&amp;S_IROTH))\r\n\t\t\t\t\t\t*mode^=S_IROTH;\r\n\t\t\t\t\tif(w&amp;&amp;(*mode&amp;S_IWOTH))\r\n\t\t\t\t\t\t*mode^=S_IWOTH;\r\n\t\t\t\t\tif(x&amp;&amp;(*mode&amp;S_IXOTH))\r\n\t\t\t\t\t\t*mode^=S_IXOTH;\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\tbreak;<\/pre>\n<p>\u6700\u540e\u662fcase3\u7684\u60c5\u51b5\u3002\u4e0e\u4e0a\u8ff0\u4e24\u79cd\u60c5\u51b5\u4e0d\u540c\u7684\u662f\uff0c=\u5e76\u4e0d\u662f\u5728\u6587\u4ef6\u539f\u6709\u7684\u6743\u9650\u4e0a\u589e\u52a0\u6216\u51cf\u5c11\u67d0\u4e2a\u6743\u9650\uff0c\u800c\u662f\u5bf9\u547d\u4ee4\u4e2d\u51fa\u73b0\u7684\u67d0\u4e2a\u7ec4\u7684\u6743\u9650\u8fdb\u884c\u8d4b\u503c\u3002\u4e5f\u5c31\u662f\u8bf4\u5b83\u4f1a\u8986\u76d6\u539f\u7ec4\u4e2d\u7684\u6743\u9650\u3002\u6bd4\u5982\uff1b\u5df2\u77e5test.c\u6587\u4ef6\u7684\u6743\u9650\u4e3a&#8211;wx-w-r&#8211;(324)\u3002\u90a3\u4e48.\/my_chmod ug=r test.c\uff1b\u540e\uff0c\u4ed6\u7684\u6743\u9650\u4e3a\uff1a-r&#8211;r&#8211;r&#8211;(444)\u3002\u53ef\u4ee5\u770b\u5230\u4ed6\u5c06ug\u4e24\u7ec4\u7684\u539f\u6743\u9650\u8986\u76d6\uff0c\u800co\u7ec4\u672a\u5728\u547d\u4ee4\u4e2d\u51fa\u73b0\uff0c\u56e0\u6b64\u4e0d\u53d7\u5f71\u54cd\u3002<\/p>\n<p>\u5728\u8fdb\u5165\u67d0\u4e2a\u7ec4\u65f6\u5019\uff0c\u6bd4\u5982\u8fdb\u5165U\u7ec4\u65f6\uff0c\u6211\u4eec\u4f1a\u8fd9\u6837\u5904\u7406mode\uff1a*mode&amp;=(S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);\u4e3a\u4f55\u8981\u8fd9\u4e48\u505a\uff1f\u5c31\u5982\u6211\u4eec\u521a\u624d\u5206\u6790\u7684\u90a3\u6837\uff0c\u6211\u4eec\u8981\u4e3a\u67d0\u4e2a\u7ec4\u8d4b\u503c\uff0c\u5fc5\u987b\u8986\u76d6\u6389\u8fd9\u4e2a\u7ec4\u539f\u6709\u6743\u9650\uff0c\u56e0\u6b64\u6211\u4eec\u5148\u5f97\u5230\u53e6\u5916\u4e24\u4e2a\u7ec4\u6240\u6709\u6743\u9650\u6216\u7684\u7ed3\u679c\uff08\u5728\u8fd9\u4e2a\u6216\u7684\u7ed3\u679c\u4e2d\uff0c\u53e6\u5916\u4e24\u4e2a\u7ec4\u6240\u6709\u6743\u9650\u5bf9\u5e94\u7684\u90a3\u4e2a\u4f4d\u5747\u4e3a1\uff09\uff0c\u548c\u6587\u4ef6\u7684\u539f\u6743\u9650\u53bb\u4e0e\uff0c\u4fbf\u53ef\u4ee5\u4f7f\u5f97U\u7ec4\u6743\u9650\u4e3a0\uff0c\u800c\u5176\u4ed6\u7ec4\u7684\u6743\u9650\u4e0d\u53d7\u5f71\u54cd\u3002\u8fd9\u5176\u5b9e\u6839\u636e\uff1a1&amp;1=1\uff0c1&amp;0=0\u3002<\/p>\n<pre class=\"brush:c\">\t\tcase 3:\r\n\t\t\t{\r\n\t\t\t\tif(u)\r\n\t\t\t\t{\r\n\t\t\t\t\t*mode&amp;=(S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);\r\n\t\t\t\t\tif(r)\r\n\t\t\t\t\t\t*mode|=S_IRUSR;\r\n\t\t\t\t\tif(w)\r\n\t\t\t\t\t\t*mode|=S_IWUSR;\r\n\t\t\t\t\tif(x)\r\n\t\t\t\t\t\t*mode|=S_IXUSR;\r\n\t\t\t\t}\r\n\t\t\t\tif(g)\r\n\t\t\t\t{\r\n\t\t\t\t\t*mode&amp;=(S_IRUSR|S_IWUSR|S_IXUSR|S_IROTH|S_IWOTH|S_IXOTH);\r\n\t\t\t\t\tif(r)\r\n\t\t\t\t\t\t*mode|=S_IRGRP;\r\n\t\t\t\t\tif(w)\r\n\t\t\t\t\t\t*mode|=S_IWGRP;\r\n\t\t\t\t\tif(x)\r\n\t\t\t\t\t\t*mode|=S_IXGRP;\r\n\t\t\t\t}\r\n\t\t\t\tif(o)\r\n\t\t\t\t{\r\n\t\t\t\t\t*mode&amp;=(S_IRGRP|S_IWGRP|S_IXGRP|S_IRUSR|S_IWUSR|S_IXUSR);\r\n\t\t\t\t\tif(r)\r\n\t\t\t\t\t\t*mode|=S_IROTH;\r\n\t\t\t\t\tif(w)\r\n\t\t\t\t\t\t*mode|=S_IWOTH;\r\n\t\t\t\t\tif(x)\r\n\t\t\t\t\t\t*mode|=S_IXOTH;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tprintf(\"sign error\\n\");\r\n\t\t\texit(1);<\/pre>\n<p>\u597d\u4e86\uff0c\u4ee5\u4e0a\u4fbf\u662f\u5982\u4f55\u5c06\u7b26\u53f7\u6743\u9650\u8f6c\u5316\u4e3a\u6570\u5b57\u6743\u9650\u3002\u6700\u7ec8\u7684mode\u4f1a\u5728check_option\u51fd\u6570\u4e2d\u5f97\u5230\uff0c\u8fd9\u4e2amode\u4f1a\u5728chmod\u51fd\u6570\u4e2d\u7528\u5230\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300aLinuxC\u7f16\u7a0b\u5b9e\u6218\u300b\u4e00\u4e66\u4e2d\u5728\u4ecb\u7ecd\u6587\u4ef6\u64cd\u4f5c\u90e8\u5206\u7684\u65f6\u5019\uff0c\u4e00\u5f00\u59cb\u5c31\u7ed9\u6211\u4eec\u4e3e\u4e86\u4e2a\u5b9e\u73b0my_chmod\u7684\u5c0f\u7a0b\u5e8f\u3002\u5b83\u53ea [&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":[132,125,107,131],"class_list":["post-960","post","type-post","status-publish","format-standard","hentry","category-linuxc","tag-chmod","tag-linux","tag-107","tag-131"],"views":8861,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/960","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=960"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/960\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=960"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}