Welcome![Sign In][Sign Up]
Location:
Search - mydu unix

Search list

[Linux-Unixmydu.tar

Description: unix du命令的简单实现,主要可以学习glob函数的使用-static int64_t mydu_getblocks(const char*path) { int i int64_t sum=0 static struct stat stat_result glob_t glob_result static int ret static char fullpath[PATHMAX] if (lstat(path, &stat_result)<0) { perror("lstat()") return 0 } if (!S_ISDIR(stat_result.st_mode)) { return stat_result.st_blocks } /************************************************/ snprintf(fullpath, PATHMAX, " s/*", path) ret = glob(fullpath, GLOB_NOCHECK|GLOB_NOSORT, NULL, &glob_result) if (ret!=0) { perror("glob()") return 0 } snprintf(fullpath, PATHMAX, " s/.*", path) ret = glob(fullpath, GLOB_NOCHECK|GLOB_NOSORT|GLOB_APPEND, NULL, &glob_result) if (ret!=0) { perror("glob()") return 0 } sum+= stat_result.st_blocks for (i=0 i<glob_result.gl_pathc ++i) { if (isvalid(glob_result.gl_pathv[i])) { sum+= mydu_getblocks(glob_result.gl_pathv[i]) } } globfree(&glob_result) return sum }
Platform: | Size: 1024 | Author: aasdf | Hits:

CodeBus www.codebus.net