zoukankan      html  css  js  c++  java
  • 如何获得iphone设备的剩余空间

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

    用法:先引入头文件   

    #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 */

      

    永远保持新人的心态,勤奋好学,不耻下问
  • 相关阅读:
    【Oracle】实体化视图
    安装Linux Centos系统硬盘分区方法
    .NET基础一
    【MySQL】无法启动mysql服务(位于本地计算机上)错误1067,进程意外中止
    Linux基础一
    SQL Server中生成100万行8位纯数字的随机数(转)
    SQL Server配置数据库邮件
    SQL点点滴滴_聪明的小写法(持续更新中)
    过去的2017和已经到来的2018
    【Oracle】PL/SQL Developer使用技巧(持续更新中)
  • 原文地址:https://www.cnblogs.com/keepFlying/p/4479497.html
Copyright © 2011-2022 走看看