原创 文件状态和属性操作

2024-6-10 15:19 203 3 3 分类: 软件与OS 文集: Linux
代码;

/*
 * main.c
 *
 *  Created on: 2024-6-10
 *      Author: root
 */

#include
#include
#include
#include
#include
#include


int main()
{
	int f;
	const char *f_path="test";
	mode_t f_attrib;
	struct stat *buf=malloc(sizeof(stat));

	f_attrib=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
			S_IROTH;
	f=creat(f_path,f_attrib);
	if(f==-1)
	{


			puts("file create failed!");


	}
	else
		puts("file create success!");
	fstat(f,buf);
	if(buf->st_mode & S_IRUSR)
		puts("all have read authority ");
	if(buf->st_mode & S_IRGRP)
		puts("group have read authority ");
	close(f);
	chmod(f_path,0771);
	stat(f_path,buf);
	if(buf->st_mode & S_IWUSR)
		puts("all have write authority ");
	if(buf->st_mode & S_IWGRP)
		puts("group have write authority ");
	free(buf);
	return 0;
}

y运行:

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条