在手机终端开发的时候,我们需要关注手机剩余空间,因为手机不像电脑一样空间宽裕,当设备空间比较少得时候需要释放空间.

用法:先引入头文件

#include <sys/param.h>

#include <sys/mount.h>

代码片段:

+ (long long) freeDiskSpaceInBytesByMB{

struct statfs buf;

long long freespace = -1;

if(statfs("/var", &buf) >= 0){

freespace = (long long)(buf.f_bsize * buf.f_bfree);

}

return freespace/1024/1024;

}

先来说说statfs这个东东,这是C语言函数,下面是官方的介绍:

#if __DARWIN_64_BIT_INO_T

struct statfs __DARWIN_STRUCT_STATFS64;

#else /* !__DARWIN_64_BIT_INO_T */

/*

* LP64 - WARNING - must be kept in sync with struct user_statfs in mount_internal.h.

*/

struct statfs {

short f_otype; /* TEMPORARY SHADOW COPY OF f_type */

short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */

long f_bsize; /* fundamental file system block size */

long f_iosize; /* optimal transfer block size */

long f_blocks; /* total data blocks in file system */

long f_bfree; /* free blocks in fs */

long f_bavail; /* free blocks avail to non-superuser */

long f_files; /* total file nodes in file system */

long f_ffree; /* free file nodes in fs */

fsid_t f_fsid; /* file system id */

uid_t f_owner; /* user that mounted the filesystem */

short f_reserved1; /* spare for later */

short f_type; /* type of filesystem */

long f_flags; /* copy of mount exported flags */

long    f_reserved2[2]; /* reserved for future use */

char f_fstypename[MFSNAMELEN]; /* fs type name */

char f_mntonname[MNAMELEN]; /* directory on which mounted */

char f_mntfromname[MNAMELEN];/* mounted filesystem */

char f_reserved3; /* For alignment */

long f_reserved4[4]; /* For future use */

};

#endif /* __DARWIN_64_BIT_INO_T */

最新文章

  1. css雪碧图生成工具4.2更新
  2. cut用法
  3. Fully differential amplifiers
  4. 实现Server.UrlEncode和Server.UrlDecode功能的js代码
  5. 双缓冲(Double Buffer)原理和使用
  6. adb服务无法启动
  7. jsp页面中EL表达式不能被解析
  8. 2017计算机学科夏令营上机考试-A判决素数个数
  9. 数塔~~dp学习_1
  10. Maximum Subarray(最大子数组)
  11. Java中的数组添加,数组相关代码
  12. 通过脚本调用MSBuild编译项目时指定Configuration(解決方案配置)和Platform(解決方案平台),Rebuid(重新生成解决方案),Clean(清理解决方案)
  13. Rxjs之创建操作符(Angular环境)
  14. #JS 窗口resize避免触发多次
  15. (转)SqlServer为大数据量表建索引
  16. c# partial使用
  17. STL中 set 和 multiset
  18. java IO之File基本操作
  19. JAVA正则表达式判断元音
  20. CenOS shell脚本

热门文章

  1. Fortify规则与CERT JAVA 安全编程规范的对照表
  2. 深入浅出ECharts系列(一)地图+散点图
  3. Python 基础【第五篇】元组和列表
  4. modelsim 仿真时出现无限迭代(iteration reach limitation)的原因及其解决办法
  5. poj 1182 食物链(关系并查集)
  6. list集合,map集合遍历
  7. arclist底层模板字段,可以调用的字段列表
  8. Extjs3 Combo实现百度搜索查询
  9. 移动硬盘安装linux系统小记
  10. percent-encode 百分号编码