首页 > Web开发 > 详细

linux仿写chmod命令

时间:2015-12-15 13:53:31      阅读:138      评论:0      收藏:0      [点我收藏+]

复制代码 代码如下:

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc,char **argv)
{
 int mode;
 int mode_u;
 int mode_g;
 int mode_o;
 char *path;
 if(argc<3)
 {
  printf("%s <mode num> <target file>\n",argv[0]);;
  exit(0);
 }

 mode = atoi(argv[1]);
 if(mode>777||mode<0)
 {
  printf("mode num error");
  exit(0);
 }
 mode_u = mode/100;
 mode_g = (mode- mode_u*100)/10;
 mode_o = mode -mode_u*100-mode_g*10;
 mode = mode_u*8*8+mode_g*8+mode_o;
 path = argv[2];
 if(chmod(path,mode)==-1)
 {
  perror("chmod error");
  exit(1);
 }
 return 0;
}

linux仿写chmod命令

原文:http://www.jb51.net/article/46833.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!