⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ls.c

📁 This is to bulid a sample linux shell.
💻 C
字号:
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>
#include <stdio.h>
                                                                                                                  
#define FALSE 0
#define TRUE 1
                                                                                                                             
extern  int alphasort();	/* prototype std lib functions */
char pathname[MAXPATHLEN];	/* variable to store current path */                                                                                                                            
int main(int argc,char *argv[])
{
  if(argc>2)
  {
	printf("daemon: Extra Arguments.\n");
	return 0;
  }
  int count,i;
  struct direct **files;
  int file_select();
  if(getwd(pathname) == 0 )
  {
    printf("daemon: Error getting path\n");
    exit(1);
  }
  count = scandir(pathname, &files, file_select, alphasort);	/*Get number of files in current directory in 'n' & the*/
  if(count <= 0) 						/*the file names in the structure 'files'.*/
  {
   printf("daemon: No files in this directory\n");
   exit(0);
  }                                                                                                                          
  for(i=1;i<count+1;++i)
  { 
   printf("%s  ",files[i-1]->d_name);
   if ((i % 9) == 0) 
    printf("\n");
  }
  printf("\n");/* flush buffer */
}                                                                                                                 
int file_select(struct direct   *entry)
{  /* ignore . and .. entries */
   if ((strcmp(entry->d_name, ".") == 0) ||
       (strcmp(entry->d_name, "..") == 0))
        return (FALSE);
   else
        return (TRUE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -