2004년 3월 10일 수요일

C에서 2GB이상 되는 file access하기(LFS)

http://freshmeat.net/articles/view/709/
http://www.unix.org/version2/whatsnew/lfs.html
http://www.suse.de/~aj/linux_lfs.html

#define _FILE_OFFSET_BITS 64 를 매일 첫 줄에 넣어주고 include하면 된다.
또한 fseek, ftell 대신 fseeko, ftello를 사용해야 한다.
왜냐하면 argument가 long인 경우는 문제가 발생할 수 있는 데
off_t type인 경우는 매크로에 의해 자동으로 off_t type의 크기가 커지기 때문에 문제가 없다.
http://www.opengroup.org/onlinepubs/009695399/functions/fseek.html

glibc 메뉴얼 참고
-----------------
_FILE_OFFSET_BITS  Macro
This macro determines which file system interface shall be used, one replacing the other. Whereas _LARGEFILE64_SOURCE makes the 64 bit interface available as an additional interface, _FILE_OFFSET_BITS allows the 64 bit interface to replace the old interface.
If _FILE_OFFSET_BITS is undefined, or if it is defined to the value 32, nothing changes. The 32 bit interface is used and types like off_t have a size of 32 bits on 32 bit systems.

If the macro is defined to the value 64, the large file interface replaces the old interface. I.e., the functions are not made available under different names (as they are with _LARGEFILE64_SOURCE). Instead the old function names now reference the new functions, e.g., a call to fseeko now indeed calls fseeko64.

This macro should only be selected if the system provides mechanisms for handling large files. On 64 bit systems this macro has no effect since the *64 functions are identical to the normal functions.

This macro was introduced as part of the Large File Support extension (LFS).

댓글 없음:

댓글 쓰기