linux 大文件相关资料

http://www.suse.de/~aj/linux_lfs.html

全面介绍

Using LFS

For using LFS in user programs, the programs have to use the LFS API. This involves recompilation and changes of programs. The API is documented in the glibc manual (the libc info pages) which can be read with e.g. "info libc".

In a nutshell for using LFS you can choose either of the following:

  • Compile your programs with "gcc -D_FILE_OFFSET_BITS=64". This forces all file access calls to use the 64 bit variants. Several types change also, e.g. off_t becomes off64_t. It's therefore important to always use the correct types and to not use e.g. int instead of off_t. For portability with other platforms you should use getconf LFS_CFLAGS which will return -D_FILE_OFFSET_BITS=64 on Linux platforms but might return something else on e.g. Solaris. For linking, you should use the link flags that are reported via getconf LFS_LDFLAGS. On Linux systems, you do not need special link flags.
  • Define _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE. With these defines you can use the LFS functions like open64 directly.
  • Use the O_LARGEFILE flag with open to operate on large files.

A complete documentation of the feature test macros like _FILE_OFFSET_BITS and _LARGEFILE_SOURCE is in the glibc manual (run e.g. "info libc 'Feature Test Macros'").

The LFS API is also documented in the LFS standard which is available at http://ftp.sas.com/standards/large.file/x_open.20Mar96.html.

《---------------------------------------------------------------------------------------------------------------------------------------------》

http://docs.python.org/release/2.1.3/lib/posix-large-files.html

of Irix, but with Solaris 2.6 and 2.7 you need to do something like:

CC="cc `getconf LFS_CFLAGS`" ./configure

On large-file-capable Linux systems, this might work:

CC='gcc -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' ./configure

《---------------------------------------------------------------------------------------------------------------------------------------------》

http://blog.csdn.net/yuhao1984/article/details/6116799

linux大文件

2011-01-04 23:51 37人阅读 评论(0) 收藏 举报

1. 如何查看linux系统的位数(32/64):

    * 直接看看有没有/lib64目目录的方法:

           64位的系统会有/lib64和/lib两个目录,32位只有/lib一个

    * getconf LONG_BIT:

          32位的系统中int类型和long类型一般都是4字节,64位的系统中int类型还是4字节的,但是long已变成了8字节

    * uname -a:

如果是64位,会有x86_64的字样

    * 用编程的方法,sizeof( long 或 size_t )就是系统的位数

这个与编译器版本有关,有时会不相符。不建议使用。所以在编程中,用可以指定int的长度int32_t,int64_t,uint32_t和uint64_t等可以避免位数问题和增强可读性

2. linux下C语言操作大文件(4G以上)

一般情况下,64位操作系统可以操作任何大文件(2^64)。

以下讨论的是32位机器的情况。

首先32位机器用fopen/fclose打开大文件没有问题,顺序读写操作while(!feof(fp)){ fread / fgets / fscanf }或while(1){ fwrite / fputs / fprintf} 也没有问题。

由于32位机器下long是32位,故

fseek (FILE *stream, long offset, int whence)

long ftell(FILE *stream) 不能访问4G以上文件

此时要用 fseeko (FILE *stream, off_t offset, int whence)

off_t ftello(FILE *stream);代替

类型off_t 的定义在 <sys/types.h>里面:

# ifndef __USE_FILE_OFFSET64
typedef __off_t off_t;
# else
typedef __off64_t off_t;
# endif
off_t在32位机器中是32bit,64位机器中是64bit。那么,在32位机器中,在include之前加入宏定义:#define _FILE_OFFSET_BITS 64,或者编译是加入-D_FILE_OFFSET_BITS 64告诉系统在文件内部使用64位的偏移地址,使off_t变成__off64_t类型。

这样,只要你用64bit的类型(off_t,long(64位机器),和long long(32位机器) 或int64_t/uint64_t)声明offset作为fseeko的参数输入,就可以操作4G以上的文件了。

许多人还提到在宏定义中多写上一些:

#define _FILE_OFFSET_BITS 64

#define _LARGEFILE_SOURCE

#define _LARGEFILE64_SOURCE

但另外两个的具体功能我现在尚未搞得很清楚,等以后了解完全再补上。

*   使用LINUX自己的库函数进行文件操作(*nix I/O操作),加入O_LARGEFILE选项:

#define __USE_LARGEFILE64

#include <fcnl.h>

int fp = open("myfile", O_WRONLY | O_TRUNC | O_CREAT | O_LARGEFILE, 644);

《---------------------------------------------------------------------------------------------------------------------------------------------》

Adding Support for Arbitrary File Sizes to the Single UNIX Specification

http://www.unix.org/version2/whatsnew/lfs20mar.html

原文地址:https://www.cnblogs.com/cute/p/2112618.html