如何在Darwin下启用大文件支持?

时间:2021-12-03 23:26:17

I have a C application I am trying to compile for Mac OS X 10.6.4:

我有一个C应用程序,我正在尝试为Mac OS X 10.6.4编译:

$ uname -v
Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386

My gcc is as follows:

我的gcc如下:

$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)

My Makefile is as follows:

我的Makefile如下:

CC=gcc
CFLAGS=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -O3 -Wformat -Wall -pedantic -std=gnu99

all: myApp
    rm -rf *~

myApp: myApp.o
    ${CC} ${CFLAGS} myApp.o -lbz2 -o myApp
    rm -rf *~

clean:
    rm -rf *.o myApp

The issue is that my application makes calls to fseeko64 and fopen64, and uses the off64_t type for offsets. When I compile my application I get the following warnings and errors:

问题是我的应用程序调用fseeko64和fopen64,并使用off64_t类型进行偏移。当我编译我的应用程序时,我收到以下警告和错误:

$ make myApp
gcc -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -O3 -Wformat -Wall -pedantic -std=gnu99   -c -o myApp.o myApp.c
myApp.c: In function ‘extractData’:
myApp.c:119: warning: implicit declaration of function ‘fseeko64’
myApp.c:119: error: ‘off64_t’ undeclared (first use in this function)
myApp.c:119: error: (Each undeclared identifier is reported only once
myApp.c:119: error: for each function it appears in.)
myApp.c: In function ‘extractMetadata’:
myApp.c:305: warning: implicit declaration of function ‘fopen64’
myApp.c:305: warning: assignment makes pointer from integer without a cast

My code builds without errors under Linux. What changes can I make to the source code to add large file support when building under Darwin?

我的代码在Linux下构建没有错误。在Darwin下构建时,我可以对源代码进行哪些更改以添加大文件支持?

3 个解决方案

#1


10  

On Darwin file I/O is 64-bit by default (10.5 at least), just found this by grepping in /usr/include:

在Darwin文件中,默认情况下I / O是64位(至少10.5),只需在/ usr / include中找到它:

sys/_types.h:typedef __int64_t  __darwin_off_t;

unistd.h:typedef __darwin_off_t     off_t;

So all you need to do is something like

所以你需要做的就是这样

#ifdef __APPLE__
#  define off64_t off_t
#  define fopen64 fopen
...
#endif

#2


3  

While this question has an up-voted accepted answer which works I think the solution is a bit misleading. Instead of fixing something it's always better to avoid having to fix it later in the first place.

虽然这个问题有一个上升的已接受的答案,但我觉得解决方案有点误导。而不是修复某些东西,最好避免以后必须在以后修复它。

For example for the fopen64 function the GNU C Library docs say:

例如,对于fopen64函数,GNU C Library文档说:

If the sources are compiled with _FILE_OFFSET_BITS == 64 on a 32 bits machine this function is available under the name fopen and so transparently replaces the old interface.

如果在32位机器上使用_FILE_OFFSET_BITS == 64编译源代码,则此函数以名称fopen可用,因此透明地替换旧接口。

You can just use the same function fopen on systems that support 64-bit I/O by default and you can set the _FILE_OFFSET_BITS=64 flag on 32-bit without the need write redefines at all. The same goes for types like off64_t vs. off_t.

您可以在默认情况下在支持64位I / O的系统上使用相同的函数fopen,并且可以在32位上设置_FILE_OFFSET_BITS = 64标志,而根本不需要写入重新定义。对于像off64_t vs. off_t这样的类型也是如此。

Save the redefines for the case when you have to deal with 3rd party sources and use standard functions in your own code.

当您必须处理第三方来源并在您自己的代码中使用标准函数时,请保留重新定义的案例。

#3


1  

The fseeko and similar commands work with large file support so no need for the fseeko64 etc Apple man page

fseeko和类似命令适用于大文件支持,因此不需要fseeko64等Apple手册页

#1


10  

On Darwin file I/O is 64-bit by default (10.5 at least), just found this by grepping in /usr/include:

在Darwin文件中,默认情况下I / O是64位(至少10.5),只需在/ usr / include中找到它:

sys/_types.h:typedef __int64_t  __darwin_off_t;

unistd.h:typedef __darwin_off_t     off_t;

So all you need to do is something like

所以你需要做的就是这样

#ifdef __APPLE__
#  define off64_t off_t
#  define fopen64 fopen
...
#endif

#2


3  

While this question has an up-voted accepted answer which works I think the solution is a bit misleading. Instead of fixing something it's always better to avoid having to fix it later in the first place.

虽然这个问题有一个上升的已接受的答案,但我觉得解决方案有点误导。而不是修复某些东西,最好避免以后必须在以后修复它。

For example for the fopen64 function the GNU C Library docs say:

例如,对于fopen64函数,GNU C Library文档说:

If the sources are compiled with _FILE_OFFSET_BITS == 64 on a 32 bits machine this function is available under the name fopen and so transparently replaces the old interface.

如果在32位机器上使用_FILE_OFFSET_BITS == 64编译源代码,则此函数以名称fopen可用,因此透明地替换旧接口。

You can just use the same function fopen on systems that support 64-bit I/O by default and you can set the _FILE_OFFSET_BITS=64 flag on 32-bit without the need write redefines at all. The same goes for types like off64_t vs. off_t.

您可以在默认情况下在支持64位I / O的系统上使用相同的函数fopen,并且可以在32位上设置_FILE_OFFSET_BITS = 64标志,而根本不需要写入重新定义。对于像off64_t vs. off_t这样的类型也是如此。

Save the redefines for the case when you have to deal with 3rd party sources and use standard functions in your own code.

当您必须处理第三方来源并在您自己的代码中使用标准函数时,请保留重新定义的案例。

#3


1  

The fseeko and similar commands work with large file support so no need for the fseeko64 etc Apple man page

fseeko和类似命令适用于大文件支持,因此不需要fseeko64等Apple手册页