亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? myfind2.c

?? 在unix下實現目錄樹的遍歷以及一些相關的內容
?? C
字號:
#include	<sys/types.h>
#include	<sys/stat.h>
#include	<dirent.h>
#include	<limits.h>
#include    <errno.h>
#include     "apue.h"
#include    <fcntl.h>
#include     <malloc.h>
#include     <string.h>

#define    MAXL 4096
typedef	int	Myfunc(const char *, const struct stat *, int);
				/* function type that's called for each filename */

static Myfunc	myfunc;
static Myfunc   myfunc2;
static Myfunc	myfunc3;
static int		myftw(char *, Myfunc *);
static int		dopath(Myfunc *);
static long	    nreg,nreg1, ndir, nblk, nchr, nfifo, nslink, nsock, ntot,total;
static char copy_argv[10][200],*name=NULL,*buff2=NULL;
static int copy_argc,length2;

int
main(int argc, char *argv[])
{
	int		ret,i,fd2;
    total=0;
	for(i=0;i<=argc-1;i++)
	   strcpy(copy_argv[i],argv[i]);
    copy_argc=argc;   
    
	if(argc==2){
           ret = myftw(argv[1],myfunc);		/* does it all */
           total=0;
	         if ( (ntot = nreg + ndir + nblk + nchr + nfifo + nslink + nsock) == 0)
		           ntot = 1;		/* avoid divide by 0; print 0 for all counts */
	         printf("regular files  = %7ld, %5.2f %%\n", nreg,  nreg*100.0/ntot);
	         printf("directories    = %7ld, %5.2f %%\n", ndir,  ndir*100.0/ntot);
	         printf("block special  = %7ld, %5.2f %%\n", nblk,  nblk*100.0/ntot);
	         printf("char special   = %7ld, %5.2f %%\n", nchr,  nchr*100.0/ntot);
	         printf("FIFOs          = %7ld, %5.2f %%\n", nfifo, nfifo*100.0/ntot);
	         printf("symbolic links = %7ld, %5.2f %%\n", nslink,nslink*100.0/ntot);
	         printf("sockets        = %7ld, %5.2f %%\n", nsock, nsock*100.0/ntot);
	         printf("length of regular files large than %d=%7ld,%5.2f %%\n ",MAXL,nreg1,nreg1*100.0/ntot);
          exit(ret);
        }
    else if((argc==4)&&((strcmp(argv[2],"-comp"))==0)){
        total=0;
        fd2=open(copy_argv[3],O_RDWR);
        length2=lseek(fd2,0,SEEK_END);
        lseek(fd2,0,SEEK_SET);
        if((buff2=(char *)malloc(sizeof(char)*length2))==NULL){			               	 
   	 	      printf("the length2 is %ld",length2);
              err_sys("malloc error!!");
        }
 	 	if((read(fd2,buff2,length2))!=length2)
          err_sys("read error!!"); 
        close(fd2);  
        ret = myftw(argv[1], myfunc2);
        if(total==0)
    	     	  printf("Not Find!!!!\n");
    }
    else if((argc>=4)&&((strcmp(argv[2],"-name"))==0)){
             total=0;
    	       ret = myftw(argv[1], myfunc3);
    	       if(total==0)
    	     	  printf("Not Find!!!!\n");
            }
            else 
       	   	    printf("input error!!!");  
}      

/*
 * Descend through the hierarchy, starting at "pathname".
 * The caller's func() is called for every file.
 */

#define	FTW_F	1		/* file other than directory */
#define	FTW_D	2		/* directory */
#define	FTW_DNR	3		/* directory that can't be read */
#define	FTW_NS	4		/* file that we can't stat */

static char	*fullpath;		/* contains full pathname for every file */

static int					/* we return whatever func() returns */
myftw(char *pathname, Myfunc *func)
{
    int len;       
	fullpath = path_alloc(&len);	/* malloc's for PATH_MAX+1 bytes */
									/* ({Prog pathalloc}) */
    strncpy(fullpath, pathname,len);	    /* initialize fullpath */
    fullpath[len-1]=0;
	return(dopath(func));
}
/*
 * Descend through the hierarchy, starting at "fullpath".
 * If "fullpath" is anything other than a directory, we lstat() it,
 * call func(), and return.  For a directory, we call ourself
 * recursively for each name in the directory.
 */
static int					/* we return whatever func() returns */
dopath(Myfunc* func)
{
	struct stat		statbuf;
	struct dirent	*dirp;
	DIR				*dp;
	int				ret;
	char			*ptr;

	if (lstat(fullpath, &statbuf) < 0)
		return(func(fullpath, &statbuf, FTW_NS));	/* stat error */

	if (S_ISDIR(statbuf.st_mode) == 0)
		return(func(fullpath, &statbuf, FTW_F));	/* not a directory */

	/*
	 * It's a directory.  First call func() for the directory,
	 * then process each filename in the directory.
	 */

	if ( (ret = func(fullpath, &statbuf, FTW_D)) != 0)
		return(ret);

	ptr = fullpath + strlen(fullpath);	/* point to end of fullpath */
	*ptr++ = '/';
	*ptr = 0;

	if ( (dp = opendir(fullpath)) == NULL)
		return(func(fullpath, &statbuf, FTW_DNR));
										/* can't read directory */

	while ( (dirp = readdir(dp)) != NULL) {
		if (strcmp(dirp->d_name, ".") == 0  ||
		    strcmp(dirp->d_name, "..") == 0)
				continue;		/* ignore dot and dot-dot */

		strcpy(ptr, dirp->d_name);	/* append name after slash */

		if ( (ret = dopath(func)) != 0)		/* recursive */
			break;	/* time to leave */
	}
	ptr[-1] = 0;	/* erase everything from slash onwards */

	if (closedir(dp) < 0)
		err_ret("can't close directory %s", fullpath);

	return(ret);
}
static int
myfunc(const char *pathname, const struct stat *statptr, int type)
{
    int fd,length;         
	switch (type) {
	case FTW_F:
		switch (statptr->st_mode & S_IFMT) {
		case S_IFREG:	{
                          nreg++; fd=open(pathname,O_WRONLY|O_CREAT,FILE_MODE);
                          if((length=lseek(fd,0,SEEK_END))<=MAXL)	
                              nreg1++;
                          close(fd);
                         	break;
                           }
		case S_IFBLK:	nblk++;		break;
		case S_IFCHR:	nchr++;		break;
		case S_IFIFO:	nfifo++;	break;
		case S_IFLNK:	nslink++;	break;
		case S_IFSOCK:	nsock++;	break;
		case S_IFDIR:
			err_dump("for S_IFDIR for %s", pathname);
					// directories should have type = FTW_D 
		}
		break;

	case FTW_D:
		ndir++;
		break;

	case FTW_DNR:
		err_ret("can't read directory %s", pathname);
		break;

	case FTW_NS:
		err_ret("stat error for %s", pathname);
		break;

	default:
		err_dump("unknown type %d for pathname %s", type, pathname);
	}

	return(0);
}
static int
myfunc2(const char *pathname, const struct stat *statptr, int type)
{
    int fd1,len;
    long length1,i;  
    char *buff1,*path,*ptr;
     /* length=strlen(pathname)*sizeof(char);
	path=(char *)malloc(length);
    for(i=length-1;pathname[i]!='/';i--) ;
	for(i=i+1,j=0;i<=length;i++,j++)
		path[j]=pathname[i];
	path[j]='\0';*/
     if(type==FTW_F){                     
             fd1=open(pathname,O_RDWR);
             length1=lseek(fd1,0,SEEK_END);
			             //  printf("%ld",length1);
             lseek(fd1,0,SEEK_SET);
             if(length1==length2){
                //  printf("%ld",length1) ;                  
                  if((buff1=(char *)malloc(sizeof(char)*length1))==NULL)
                     err_sys("malloc error!!");
                  if((read(fd1,buff1,length1))!=length1)
                     err_sys("read error!!"); 
                  for(i=0;i<=length2-1;i++)
                     if(buff1[i]!=buff2[i])
                            break;
                  if(i>=length2){
   	                total++;
                    ptr=path_alloc(&len);
                    if(getcwd(ptr,len)!=NULL){
                        strcat(ptr,&pathname[1]);
			 	        printf("%s\n",ptr);            
                     }
                     free(buff1);
                     close(fd1);
                 }
             }
    }
 	return(0);
}
static int
myfunc3(const char *pathname, const struct stat *statptr, int type)
{
    int i,len;  
    char *path,*ptr;       
	switch (type){ 
	  case FTW_F:	for(i=3;i<=copy_argc-1;i++){
                        // printf("%s",copy_argv[i]) ; 
                       if((path=(char *)malloc(strlen(copy_argv[i])*sizeof(char)))==NULL)	
                            err_quit("malloc error\n");                  
                       strcpy(path,&pathname[strlen(pathname)-strlen(copy_argv[i])]);                        
                       if((strcmp(path,copy_argv[i]))==0){
                          total++;
                         // printf("%s\n",pathname);
                          ptr=path_alloc(&len);
                          if(getcwd(ptr,len)==NULL)
                             err_sys("getcwd failed");  
                           strcat(ptr,pathname);           
                           printf("%s\n",ptr);
                           }
                      }
                      break;
  }
	return(0);
}
#ifdef PATF_MAX
static int pathmax=PATH_MAX;
#else 
static int  pathmax=0;
#endif
#define  SUSV3    200112L
static long posix_version=0;
#define  PATH_MAX_GUESS 1024
char * path_alloc(int *sizep)
{
     char *ptr;
     int size;
     if(posix_version==0)
        posix_version=sysconf(_SC_VERSION);
     if(pathmax==0){
          errno=0;
          if((pathmax=pathconf("/",_PC_PATH_MAX))<0){
               if(errno==0)
                   pathmax=PATH_MAX_GUESS;
               else 
                   err_sys("pathconf error for _PC_PATH_MAX");
            }
          else {
             pathmax++;
          }
      }
      if(posix_version<SUSV3)
         size=pathmax+1;
         else 
            size=pathmax;
      if((ptr=malloc(size))==NULL)
          err_sys("mallco error for pathname");
      if(sizep!=NULL)
          *sizep=size;
     return(ptr);
}            
                          













?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品亚洲第一| 日韩欧美另类在线| 精品视频资源站| 久久久精品免费免费| 亚洲国产成人av好男人在线观看| 国产精品亚洲人在线观看| 7777精品伊人久久久大香线蕉 | 免费人成网站在线观看欧美高清| 国产一区二区三区日韩| 欧美日韩国产小视频| 国产精品国模大尺度视频| 免费xxxx性欧美18vr| 欧美色综合网站| 国产精品夫妻自拍| 韩国欧美一区二区| 日韩一区二区在线观看视频| 一区二区三区成人在线视频| av动漫一区二区| 欧美国产一区视频在线观看| 久久精品国产亚洲高清剧情介绍 | 亚洲一本大道在线| www.性欧美| 亚洲国产成人午夜在线一区| 国产一区二区导航在线播放| 欧美一级二级在线观看| 香蕉久久一区二区不卡无毒影院| 91视视频在线直接观看在线看网页在线看 | 欧美日本韩国一区二区三区视频| 国产精品美女久久久久久久久 | 五月综合激情婷婷六月色窝| 色偷偷一区二区三区| 中文字幕一区二区视频| 成人激情午夜影院| 国产精品久久久久一区二区三区 | 免费精品视频最新在线| 在线播放欧美女士性生活| 五月天一区二区三区| 欧美日韩国产a| 亚洲成人av中文| 欧美一区二区视频网站| 麻豆成人综合网| 欧美岛国在线观看| 精彩视频一区二区| 久久久一区二区三区| 99久久精品国产麻豆演员表| 亚洲日本va在线观看| 日本韩国欧美三级| 三级欧美在线一区| 欧美大胆一级视频| 国产精品小仙女| 中文字幕日韩一区| 欧美精品九九99久久| 久久97超碰色| 欧美国产日产图区| 欧美四级电影网| 久草这里只有精品视频| 国产婷婷一区二区| 欧美视频中文字幕| 久久不见久久见免费视频7| 国产视频一区二区三区在线观看| 国产xxx精品视频大全| 亚洲美腿欧美偷拍| 日韩免费观看高清完整版在线观看| 狠狠色丁香久久婷婷综| 亚洲老司机在线| 久久综合色婷婷| 成人精品电影在线观看| 亚洲电影一级片| 久久久久久久网| 一本到一区二区三区| 麻豆成人av在线| 亚洲精品国产a| 精品处破学生在线二十三| 色婷婷亚洲综合| 黄一区二区三区| 亚洲精品久久久久久国产精华液 | 在线亚洲免费视频| 久久超碰97中文字幕| 一区二区三区成人在线视频| 久久综合色播五月| 欧美日韩国产天堂| eeuss鲁片一区二区三区在线看| 污片在线观看一区二区| 亚洲色图清纯唯美| 26uuu国产日韩综合| 精品视频一区三区九区| 99久久久无码国产精品| 老司机精品视频一区二区三区| 亚洲免费观看高清完整 | 欧美日韩国产一区| 99精品国产视频| 国产成人av一区二区三区在线 | 色综合视频一区二区三区高清| 日本不卡中文字幕| 一区二区欧美在线观看| 中文字幕一区三区| 亚洲大片一区二区三区| www.亚洲在线| 韩国成人精品a∨在线观看| 午夜视频一区在线观看| 亚洲欧美在线视频| 中文字幕欧美三区| 精品99999| 日韩精品一区二区三区在线 | 亚洲成a人在线观看| 亚洲日本成人在线观看| 国产精品免费丝袜| 欧美国产精品专区| 久久婷婷色综合| 精品国产乱码久久久久久闺蜜| 欧美高清dvd| 欧美日韩在线亚洲一区蜜芽| 日本福利一区二区| 一本高清dvd不卡在线观看| www.欧美.com| 成人sese在线| 99久久精品国产一区| 91丝袜高跟美女视频| 91成人看片片| 欧美日韩亚洲综合在线 欧美亚洲特黄一级| 高清国产午夜精品久久久久久| 国产一区二区三区香蕉| 国产jizzjizz一区二区| 成人免费黄色大片| 99re视频这里只有精品| 91日韩一区二区三区| 欧美三级电影精品| 69堂亚洲精品首页| 欧美大度的电影原声| 国产色产综合产在线视频| 欧美激情中文不卡| 亚洲欧美日本在线| 亚洲国产成人va在线观看天堂| 日韩主播视频在线| 久久99精品国产91久久来源| 粉嫩一区二区三区在线看| 成人精品gif动图一区| 在线观看亚洲成人| 日韩一区二区三区观看| 久久久精品蜜桃| 亚洲视频在线一区二区| 午夜免费欧美电影| 国模一区二区三区白浆| 91碰在线视频| 欧美变态tickling挠脚心| 欧美极品aⅴ影院| 亚洲国产精品久久人人爱蜜臀| 免费不卡在线观看| 91在线国内视频| 欧美一区二区精美| 国产农村妇女精品| 亚洲一区二区精品视频| 极品尤物av久久免费看| 99九九99九九九视频精品| 在线电影欧美成精品| 国产日韩欧美在线一区| 亚洲乱码精品一二三四区日韩在线| 亚洲一区二区三区四区中文字幕 | 精品成人在线观看| 国产精品电影一区二区三区| 亚洲成人免费在线| 成人网页在线观看| 日韩小视频在线观看专区| 国产精品视频你懂的| 麻豆精品新av中文字幕| 色综合久久中文字幕综合网| 欧美xxxx老人做受| 亚洲制服欧美中文字幕中文字幕| 国产一区二区三区免费观看| 欧美三级中文字幕| 亚洲欧洲av一区二区三区久久| 老司机精品视频在线| 欧美性色综合网| 中文字幕一区二区三区在线不卡 | 国产·精品毛片| 日韩欧美自拍偷拍| 亚洲一二三四在线| kk眼镜猥琐国模调教系列一区二区| 欧美一区二区三区思思人| 伊人色综合久久天天| 国产乱人伦精品一区二区在线观看| 欧美喷水一区二区| 亚洲一区二区三区四区中文字幕| 成人激情综合网站| 中文子幕无线码一区tr| 极品少妇xxxx精品少妇| 日韩一区二区电影| 首页国产欧美日韩丝袜| 欧美日韩三级在线| 亚洲精品第1页| 91免费视频大全| 国产精品成人一区二区三区夜夜夜| 国产成人一区二区精品非洲| 精品国产乱码久久久久久蜜臀 | 欧美日韩精品高清| 亚洲一区二区在线免费观看视频| 91一区二区在线观看| 亚洲欧洲精品一区二区三区| 成人污视频在线观看| 亚洲国产高清在线|