一见

获取指定目录大小函数源码

`static __thread off_t dirsize; // 目录大小
static int _du_fn(const char *fpath, const struct stat *sb, int typeflag)
{
if (FTW_F == typeflag)
dirsize += sb->st_size;
return 0;
}

// 获取指定目录大小函数(线程安全,但仅适用Linux)
// 遍历方式实现,低性能
off_t du(const char* dirpath)
{
dirsize = 0;
return (ftw(dirpath, _du_fn, 0) != 0)? : dirsize;
}
`

posted on 2020-07-20 17:28  -见  阅读(167)  评论(0编辑  收藏  举报

导航