IO进程线程day3

void get_fileper(mode_t m)
{
	char per[3]="rwx";
	for(int i=0;i<9;i++)
	{
		if(m&(0400>>i))
		{
			putchar("-");
			continue;
		}
		putchar(per[i%3])

	}

}

void get_fileType(mode_t m)
{
	if( S_ISREG(m))
		putchar('-');
	else if(S_ISDIR(m))
		putchar('d');
	else if(S_ISCHR(m))
		putchar('c');
	else if(S_ISBLK(m))
		putchar('b');
	else if(S_ISFIFO(m))
		putchar('p');
	else if(S_ISLNK(m))
		putchar('l');
	else if(S_ISSOCK(m))
		putchar('s');
}




int main(int argc, const char *argv[])
{
	struct stat buf;
	if(stat(argv[1],&buf)<0)
	{
		perror("stat");
		return -1;
	}

	printf("mode:0%o\n",buf,st_mode); 	
	
	get_fileper(buf.st_mode);
	get_fileType(buf.st_mode);

	ptintf("links:%d\n",buf.st_nlink); 		

	ptintf("uid:%d\n",buf,st_uid); 			
	struct passwd* pwd = getpwuid(buf.st_uid);
	if(NULL == pwd)
	{
		perror("getpwuid");
		return -1
	}
	printf("usrname:%s\n",pwd->pw_name);


	printf("gid:%d\n",buf,st_gid); 			
	struct group* grp = getgrgid(buf.st_gid);
	if(NULL == grp)
	{
		perror("getgrgid");
		return -1
	}
	printf("grpname:%s\n",grp->gr_name);


	printf("size:%ld\n",buf,st_size); 		

	printf("time:%ld\n",buf,st_ctime); 		

			return 0;
}

IO进程线程day3_第1张图片

你可能感兴趣的:(嵌入式硬件)