#include <stdio.h> #include <stdlib.h> #include <glob.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #define PATHSIZE 1024 static int path_noloop(const char *path) { char *pos; pos = strrchr(path,'/');//定位最右边的'/'的位置 , || (strcmp(pos+,)) ; ; } static int64_t mydu(const char *path) { int i; glob_t globres; int64_t sum; static struct stat statres; static char nextpath[PATHSIZE]; ) { perror("lstat()"); ;//exit(1); } if(!S_ISDIR(statres.st_mode)) return statres.st_blocks; strncpy(nextpath, path,PATHSIZE); strncat(nextpath, "/*" , PATHSIZE); glob(nextpath,GLOB_NOSORT, NULL, &globres); strncpy(nextpath, path,PATHSIZE); strncat(nextpath, "/.*" , PATHSIZE); glob(nextpath,GLOB_NOSORT|GLOB_APPEND, NULL, &globres); sum = statres.st_blocks; ;i < globres.gl_pathc ; i++) { if(path_noloop(globres.gl_pathv[i])) sum += mydu(globres.gl_pathv[i]); } return sum; } int main(int argc,char **argv) { ) { fprintf(stderr,"Usage...\n"); exit(); } printf(])); ; }