服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - linux仿写chmod命令

linux仿写chmod命令

2022-12-26 13:42linux教程网 Linux

这篇文章主要介绍了linux仿写chmod命令的方法,需要的朋友可以参考下

复制代码 代码如下:

#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;
}

 

延伸 · 阅读

精彩推荐