您现在的位置是:网站首页> 编程资料编程资料

linux仿写chmod命令_linux shell_

2023-05-26 332人已围观

简介 linux仿写chmod命令_linux shell_

复制代码 代码如下:

#include
#include
#include
#include
int main(int argc,char **argv)
{
 int mode;
 int mode_u;
 int mode_g;
 int mode_o;
 char *path;
 if(argc<3)
 {
  printf("%s \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;
}

-六神源码网