zoukankan      html  css  js  c++  java
  • 32位Linux下使用2G以上大文件的几个相关宏的关系

    32位LINUX使用超过2G的大文件,需要定义很多宏,与文件操作API相关的宏都有这样一些:
    _FILE_OFFSET_BITS
    _LARGEFILE_SOURCE
    _LARGEFILE64_SOURCE
    __USE_FILE_OFFSET64
    __USE_LARGEFILE
    __USE_LARGEFILE64

    那么,它们之间的关系究竟是怎么样的呢?
    终于在linux的头文件 /usr/include/features.h中找到了定义。

    //原来这个文件就是专门让用户定义各种特性的:
    /*These are defined by the user (or the compiler)
    to specify the desired environment

    其中几个供用户配置的宏的注释为:
    _LARGEFILE_SOURCE    Some more functions for correct standard I/O.
    _LARGEFILE64_SOURCE    Additional functionality from LFS for large files.
    _FILE_OFFSET_BITS=N    Select default filesystem interface.
    _GNU_SOURCE        All of the above, plus GNU extensions.
    __USE_LARGEFILE    Define correct standard I/O things.
    __USE_LARGEFILE64    Define LFS things with separate names.
    __USE_FILE_OFFSET64    Define 64bit interface as default.
    */

    // use前缀的宏定义都先取消掉,说明这些宏不是直接供用户使用的,而是由其他宏的定义衍生这些宏
    #undef    __USE_LARGEFILE
    #undef    __USE_LARGEFILE64
    #undef    __USE_FILE_OFFSET64

    //   _GNU_SOURCE是一张很大的通行证,定义了这个,很多相关的开关都会打开
    /* If _GNU_SOURCE was defined by the user, turn on all the other features.  */
    #ifdef _GNU_SOURCE
    # undef     _LARGEFILE64_SOURCE
    # define _LARGEFILE64_SOURCE    1
    #endif

    // 下面是打开各个USE宏的位置
    #ifdef _LARGEFILE_SOURCE
    # define __USE_LARGEFILE    1
    #endif

    #ifdef _LARGEFILE64_SOURCE
    # define __USE_LARGEFILE64    1
    #endif

    #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
    # define __USE_FILE_OFFSET64    1
    #endif

    总结:
    ·使用64位大文件,定义_LARGEFILE64_SOURCE和_FILE_OFFSET_BITS=64这两个宏即可

  • 相关阅读:
    leetcode 141 环形链表
    [转载]Tensorflow中reduction_indices 的用法
    SIFT特征原理与理解
    numpy切片和布尔型索引
    IPython的使用
    [文献阅读]基于卷积神经网络的高光谱图像深度特征提取与分类
    验证码校验
    防止表单重复提交
    MyBatis 一对一,一对多,多对多
    MySQL基础内容
  • 原文地址:https://www.cnblogs.com/xiayong123/p/3717094.html
Copyright © 2011-2022 走看看