1-12、讯为系统编程chmod

程序源码

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc,char *argv[])
{
	int fd,ret;
	if(argc < 3){
		printf("\nPlease input file path \n");
		return 1;
	}
//chmod test
	ret = chmod(argv[1],0777);
	if(ret < 0){
		printf("Please make sure file path\n");
		return 1;
	}
	printf("chmod %s is success!\n",argv[1]);
//fchmod test
	fd = open(argv[2],O_RDWR|O_NOCTTY|O_NDELAY);
	if(fd < 0){
		printf("Please make sure file path\n");
		return 1;
	}
	ret = fchmod(fd,0555);
	if(ret){
		printf("Please make sure file path\n");
		return 1;
	}
	printf("fchmod %s is success!\n",argv[2]);
	return 0;
}
发布了113 篇原创文章 · 获赞 1 · 访问量 1213

猜你喜欢

转载自blog.csdn.net/poor_guy_liu/article/details/103576120