Difference between revisions of "Large file support with C"

From Notes_Wiki
(Created page with "=Large file support with C= By default on 32-bit operating systems fprintf, fwrite etc. use integer for maintaining location of next read/write operation in file. Hence max 2...")
 
m
Line 1: Line 1:
<yambe:breadcrumb self="Large file support with C">C|C</yambe:breadcrumb>
=Large file support with C=
=Large file support with C=


Line 15: Line 16:


Use '<tt>getconf LFS_CFLAGS</tt>' command to see which flags work for given compiler to make it support large files. For example on 64-bit systems  '<tt>getconf LFS_CFLAGS</tt>' does not returns anything, as nothing special is required for supporting large files on 64-bit systems.
Use '<tt>getconf LFS_CFLAGS</tt>' command to see which flags work for given compiler to make it support large files. For example on 64-bit systems  '<tt>getconf LFS_CFLAGS</tt>' does not returns anything, as nothing special is required for supporting large files on 64-bit systems.
<yambe:breadcrumb self="Large file support with C">C|C</yambe:breadcrumb>

Revision as of 05:48, 18 September 2018

<yambe:breadcrumb self="Large file support with C">C|C</yambe:breadcrumb>

Large file support with C

By default on 32-bit operating systems fprintf, fwrite etc. use integer for maintaining location of next read/write operation in file. Hence max 2GB can be read or written using fprintf, fwrite, etc. ls -lh may show the same value as 2.1GB on some operating systems.

In order for these functions to write files bigger then 2GB large file support should be enabled. To enable large file support define following variables in source code.

#define _LARGEFILE_SOURCE _
#define FILE_OFFSET_BITS 64

Same can be achieved during compilation using:

gcc `getconf LFS_CFLAGS` example.c -o example

Use 'getconf LFS_CFLAGS' command to see which flags work for given compiler to make it support large files. For example on 64-bit systems 'getconf LFS_CFLAGS' does not returns anything, as nothing special is required for supporting large files on 64-bit systems.


<yambe:breadcrumb self="Large file support with C">C|C</yambe:breadcrumb>