#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
//目录类型
int leixing(mode_t m)
{
if(S_ISREG(m))
putchar('-');
else if(S_ISBLK(m))
putchar('b');
else if(S_ISCHR(m))
putchar('c');
else if(S_ISDIR(m))
putchar('d');
else if(S_ISLNK(m))
putchar('l');
else if(S_ISSOCK(m))
putchar('s');
else if(S_ISFIFO(m))
putchar('p');
}
//文件权限
int quanxian(mode_t m)
{
int i = 0, res = 0;
for(i=8; i>=0; i--)
{
if((m & 1<<i) == 0)
{
putchar('-');
}else
{
res = i % 3;
if(res == 2)
{
putchar('r');
}else if(res == 1)
{
putchar('w');
}else
{
putchar('x');
}
}
}
printf(" ");
}
//硬链接数
int llianjie(nlink_t m)
{
printf("%ld ",m);
return 0;
}
//用户名
int myuid(uid_t uid)
{
struct passwd *p = getpwuid(uid);
printf("%s ",p->pw_name);
return 0;
}
//组名
int mygrp(gid_t gid)
{
struct group *p = getgrgid(gid);
printf("%s ",p->gr_name);
return 0;
}
//文件大小
int mysize(off_t m)
{
printf("%6ld ",m);
return 0;
}
//时间
int mytime(time_t m)
{
struct tm *p = localtime(&m);
printf("%2d月 %2d %02d:%02d ",p->tm_mon+1,p->tm_mday, p->tm_hour,p->tm_min);
return 0;
}
————————————————
版权声明:本文为CSDN博主「来日定方长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_56095954/article/details/126076960
io线程作业
最新推荐文章于 2023-12-18 01:44:34 发布