我如何能够方便地打开大文件支持? [英] How can I portably turn on large file support?

查看:162
本文介绍了我如何能够方便地打开大文件支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个C程序读取和写入可能超过2GB的文件。在Linux上的 feature_test_macros (7)规定:


  _LARGEFILE64_SOURCE
          暴露的定义由LFS(大文件峰会)指定的替代API为转录
          。sitional延伸到统一UNIX规范(见⟨http://opengroup.org/platform
          /lfs.html⟩)替代API由一组新的对象(即,函数和类型)
          其名称为后缀64(例如,off64_t与off_t,lseek64()与了lseek(),等等)。
          新程序不应该使用这个接口;代替_FILE_OFFSET_BITS = 64应该采用。   _FILE_OFFSET_BITS
          定义这个宏,其值为64自动转换引用到32位功能,
          数据类型文件I / O和文件系统操作到他们的64位国家有关引用
          terparts。这对于大文件(大于2千兆字节)执行I / O有用的32位系统。
          (定义这个宏,允许正确写入使用大文件只用recompi-方案
          被要求相关特征研)64位系统自然允许文件大小超过2千兆字节,
          和在这些系统中,这个宏不起作用。


这是保证是便携式?

的Solaris建议在 lfcompile (5):


 应用程序可以在大型文件汇编编译
 环境,通过使用以下方法:     o使用在getconf(1)工具与一个或多个的
          下表中列出的参数。此方法是
          推荐用于便携式应用。          ____________________________________________________________
         |参数|目的|
         | __________________ | ________________________________________ |
         | LFS_CFLAGS |获得必要的编译标志|
         | |使大文件汇编|
         | |环境|
         | LFS_LDFLAGS |获取链接编辑器选项|
         | LFS_LIBS |获得链接库名|
         | LFS_LINTFLAGS |获得lint选项|
         | __________________ | ________________________________________ |     o将编译时标志_FILE_OFFSET_BITS 64
          之前包括任何头。应用程序可能的COM
          在大文件编译产生的茎对象
          环境中的过渡产生的对象
          TIONAL编译环境,但一定要小心
          相对于那些之间的互操作性
          对象。应用程序不应该声明全局
          类型的大小的COM之间变化的变量
          pilation环境。


这是便携式?在我的Linux机器,通过这些键的在getconf 将输出什么。 (这意味着键存在)。

有没有移植性的方法?


解决方案

使用 confstr 接口或相应的 在getconf 计划,并尝试不同的 _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 等选项,直到你找到一个工作。这会给你 CFLAGS LDFLAGS LIBS 需要一个合适的环境。

I am currently writing a C program that reads and writes files that might be over 2 GiB in size. On linux feature_test_macros(7) specifies:

   _LARGEFILE64_SOURCE
          Expose definitions for the alternative API specified by the LFS (Large File Summit) as a  "tran‐
          sitional  extension"  to  the  Single  UNIX  Specification.  (See ⟨http://opengroup.org/platform
          /lfs.html⟩) The alternative API consists of a set of new objects  (i.e.,  functions  and  types)
          whose names are suffixed with "64" (e.g., off64_t versus off_t, lseek64() versus lseek(), etc.).
          New programs should not employ this interface; instead _FILE_OFFSET_BITS=64 should be employed.

   _FILE_OFFSET_BITS
          Defining this macro with the value 64 automatically converts references to 32-bit functions  and
          data  types related to file I/O and file system operations into references to their 64-bit coun‐
          terparts.  This is useful for performing I/O on large files (> 2 Gigabytes) on  32-bit  systems.
          (Defining  this macro permits correctly written programs to use large files with only a recompi‐
          lation being required.)  64-bit systems naturally permit file sizes greater  than  2  Gigabytes,
          and on those systems this macro has no effect.

Is this guaranteed to be portable?

Solaris suggests in lfcompile(5):

 Applications can be compiled in the large  file  compilation
 environment by using the following methods:

     o    Use the getconf(1) utility with one or more of  the
          arguments listed in the table below. This method is
          recommended for portable applications.

          ____________________________________________________________
         |     argument     |                 purpose                |
         |__________________|________________________________________|
         | LFS_CFLAGS       |  obtain compilation flags necessary  to|
         |                  |  enable   the  large  file  compilation|
         |                  |  environment                           |
         | LFS_LDFLAGS      |  obtain link editor options            |
         | LFS_LIBS         |  obtain link library names             |
         | LFS_LINTFLAGS    |  obtain lint options                   |
         |__________________|________________________________________|

     o    Set the compile-time flag _FILE_OFFSET_BITS  to  64
          before including any headers. Applications may com-
          bine objects produced in the large file compilation
          environment  with  objects  produced in the transi-
          tional compilation environment, but must be careful
          with  respect  to  interoperability  between  those
          objects. Applications  should  not  declare  global
          variables of types whose sizes change between  com-
          pilation environments.

Is this portable? On my linux machine, passing these keys to getconf will output nothing. (Which means the keys exist).

Is there any portable approach?

解决方案

Use the confstr interface or the corresponding getconf program and try the various _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS, etc. options until you find one that works. This will give you CFLAGS, LDFLAGS, and LIBS needed for an appropriate environment.

这篇关于我如何能够方便地打开大文件支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆