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

2150阅读 0评论2020-07-20 aquester
分类:C/C++


  1. static __thread off_t dirsize; // 目录大小
  2. static int _du_fn(const char *fpath, const struct stat *sb, int typeflag)
  3. {
  4.     if (FTW_F == typeflag)
  5.         dirsize += sb->st_size;
  6.     return 0;
  7. }

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

上一篇:将资源文件编译成源代码文件
下一篇:JSON的schema进阶