91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-10
  • 語言: 其他
  • 標簽: linux??ls??

資源簡介

自己c實現linux下ls的兩個選項 給大家提供個思路

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
void?show_l(char?*filenameint?*cnt);
int?main(int?argc?char?*argv[]?)
{
int?count?=?0;
DIR?*dp;
struct?dirent?*dirp;
char?*filepath=“.“;
if?((dp?=?opendir(filepath))?==?NULL)
{
perror(“open?:“);
exit(1);
}
//printf(“argc?=?%d\targv[1]?=?%s\n“argcargv[1]);
while?((dirp?=?readdir(dp))?!=?NULL)
{
if?(argc?==?1)
{
if?(dirp->d_name[0]?==‘.‘)
continue;
printf(“%s\t“dirp->d_name);
continue;
}
if?(strcmp(argv[1]?“-a“)?==?0)
{
printf(“%s\t“dirp->d_name);
}
else
if?(strcmp(argv[1]?“-l“)?==?0)
{
if?(dirp->d_name[0]?==‘.‘)
continue;
show_l(dirp->d_name&count);
}
else
{
printf(“參數出錯.\n“);
break;
}
}
printf(“\n“);
closedir(dp);
return?0;
}

void?show_l(char?*filenameint?*cnt)
{
/*drwxr-xr-x?2?root?root?4096?10-17?19:58?cs
-rwxr-xr-x?1?root?root?5520?10-17?20:03?list
*/
struct?stat?buf;
if?(stat(filename&buf)? {
printf(“%s\n“filename);
exit(1);
}
//printf(“%s\n“filename);
//*cnt?+=?buf.st_blocks;

if?(S_ISREG(buf.st_mode))
printf(“-“);
else?if?(S_ISDIR(buf.st_mode))
printf(“d“);
else if?(S_ISCHR(buf.st_mode))
printf(“c“);
else if?(S_ISBLK(buf.st_mode))
printf(“b“);
else if?(S_ISFIFO(buf.st_mode))
printf(“f“);
else if?(S_ISLNK(buf.st_mode))
printf(“l“);
else if?(S_ISSOCK(buf.st_mode))
printf(“s“);
else
printf(“*“);

if?(((buf.st_mode)?&S_IRUSR)?==??S_IRUSR)
printf(“r“);
else
printf(“-“);
if?(S_IWUSR?==?(buf.st_mode?&?S_IWUSR))
printf(“w“);
else
printf(“-“);

if?((S_IXUSR?==?(buf.st_mode?&?S_IXUSR))?&&?(S_ISUID?==?(buf.st_mode?&?S_ISUID)))
printf(“s“);
else if?(S_IXUSR?==?(buf.st_mode?&?S_IXUSR))
printf(“x“);
else?if?(S_ISUID?==?(buf.st_mode?&?S_ISUID))
printf(“S“);
else
printf(“-“);

if?(S_IRGRP?==?(buf.st_mode?&?S_IRGRP))
printf(“r“);
else
printf(“-“);
if?(S_IWGRP?==?(buf.st_mode?&?S_IWGRP))
printf(“w“);
else
printf(“-“);

if?((S_IXGRP?==?(buf.st_mode?&?S_IXGRP))?&&?(S_ISGID?==?(buf.st_mode?&?S_ISGID)))
printf(“s“);
else if?(S_IXGRP?==?(buf.st_mode?&?S_IXGRP))
printf(“x“);
else?if?(S_ISGID?==?(buf.st_mode?&?S_ISGID))
printf(“S“);
else
printf(“-“);

if?(S_IROTH?==?(buf.st_mode?&?S_IROTH))
printf(“r“);
el

評論

共有 條評論